1. 程式人生 > >crm客戶列表及聯絡人新增中的問題

crm客戶列表及聯絡人新增中的問題

我在聯絡人新增頁面中,處理聯絡人所選客戶的方法是開啟一個新視窗,顯示的是客戶列表(此處直接呼叫CustomerAction_list),由使用者點選選中所屬的客戶,如下:

顯示客戶列表的視窗仍然是customer_list.jsp,只不過使用了struts2的標籤對最右欄的操作進行了更改,具體實現如下:

linkMan_add.jsp:

設定隱藏域(cust_id用於表單提交,cust_name用於linkMan_add.jsp中的資料回顯):

<input type="hidden" name="customer.cust_id" style="WIDTH: 180px" id="cust_id" />
<input type="text" style="WIDTH: 180px" id="cust_name" />

點選選擇客戶按鈕,觸發JQuery函式(window.open()),開啟一個新視窗,其中url引數為CustomerAction_list,不過為了區分請求是來自客戶頁面還是聯絡人頁面,在CustomerAction_list後加引數select=true;

<input type="button" value="選擇客戶" onclick="window.open('${pageContext.request.contextPath}/CustomerAction_list?select=true','','width=600,height=300')" >

CustomerAction_list:

準備資料,跳轉Customer_list.jsp頁面

Customer_list.jsp:

設定隱藏域,放置用以區分請求的標記:

<input type="hidden" name="select" id="select" value="<s:property value="#parameters.select" />" >

此標記在form表單內,所以在頁面跳轉時也會提交,不會出現點選下一頁就沒有了選擇按鈕的情況。

在列表的操作欄加入以下程式碼:

<s:if test="#parameters.select==null">
	<a href="${pageContext.request.contextPath }/CustomerAction_toEdit?cust_id=<s:property value="#cust.cust_id" />">修改</a>
	&nbsp;&nbsp;
	<a href="${pageContext.request.contextPath }/customerServlet?method=delete&custId=${customer.cust_id}">刪除</a>
</s:if>
<s:else>
	<input type="button" value="選擇" onclick="selectCustomer(<s:property value="#cust.cust_id" />,'<s:property value="#cust.cust_name" />')" />
</s:else>

點選選擇按鈕觸發JS函式,引數為選中客戶的id和name:

選擇按鈕:

<input type="button" value="選擇" onclick="selectCustomer(<s:property value="#cust.cust_id" />,'<s:property value="#cust.cust_name" />')" />

Js程式碼:

js程式碼的作用是獲得LinkMan_add.jsp頁面物件,設定隱藏域內的cust_id(用於資料庫提交)和cust_name(用於所選客戶回顯),然後關閉此視窗

function selectCustomer(cust_id,cust_name){
		//獲得新增頁面的額Windows物件
		var win=window.opener;
		//獲得新增頁面的document頁面
		var doc=win.document;
		//獲得隱藏域和文字框並賦值
		doc.getElementById("cust_id").value=cust_id;
		doc.getElementById("cust_name").value=cust_name;
		//關閉當前視窗
		window.close();		
	}

當我完成以上程式碼後,聯絡人的新增功能就實現好了,但我回頭點進客戶列表時,卻發現了一個問題:

客戶列表第一頁顯示正常:

點選第二頁時操作欄處發生了bug(客戶列表操作欄應為修改和刪除):

我加入了<s:debug></s:debug>標籤除錯時發現,在導航欄點選客戶列表進入Customer_list.jsp後,傳遞引數的確為空:

就是上上圖所顯示的內容,一切正常。

此時Customer_list.jsp隱藏域內的標記引數select為Null

而當我點選下一頁時,bug就出現了,頁面攜帶引數也不為null:

 我對傳入的select屬性在頁面彈窗進行了顯示,為空。我猜想空表單提交值既然不為NULL,就一定為空,所以我加入了select值的判定:

 alert("<s:property value="#parameters.select==''?'空串':'不是'"/>"); 

隱藏域內的html為空提交時,得到的結果既不為null,也不為空串。我甚至用到了trim(),但bug還是沒能解決。

經過我一系列的測試,最終得出結論:

即使<s:property value="#parameters.select" />為null,賦值給input標籤的value,提交後也不為null,但為啥也不為空串我還不能理解,因為在我的測試demo中,text中什麼都不填提交後應該為空串。

但這些對我解決這個bug沒有太大幫助,我決定另闢蹊徑,最終這麼解決的:

<!-- 放置是否需要選擇的標記引數 --> 
<s:if test="#parameters.select==null">
											
</s:if>
<s:else>
	<input type="hidden" name="select" id="select" value="<s:property value="#parameters.select" />" >
</s:else>