1. 程式人生 > >兩種動態下拉框及動態預設選擇

兩種動態下拉框及動態預設選擇

  第一種:

 action:

HttpServletRequest request = ServletActionContext.getRequest();
this.dwList = this.xlcjDao.findAllByKdm(this.dwdm);

jsp:

<%
    List dwList = (List) request.getAttribute("dwList");
%>
<td align="left">
    <select name="seldwdm<%=xh%>" onChange="change(this.value,'<%=xh%>')">
        <option value="">請選擇</option>
	    <%
		for (int i = 0; i < dwList.size(); i++) {
		    Map map =(Map) dwList.get(i);
            %>
        <option value="<%=map.get("DWDM")%>"<%if(map.get("DWDM")!=null&&map.get("DWDM").equals(anotherMap.get("DWDM")))out.print("selected"); %>><%=map.get("DWMC")%></option>
            <%  }%>
    </select>
</td>

第二種:

action:

	public String zygzlAdd(){
		init();
		Map map = new HashMap();
		csmcList = this.hkcblrDAO.getCsmcList(map);		
		map.put("dwdm", dwdm);
		//sgdwList = this.hkcblrDAO.getSgdwList(map);//施工單位list
		dwList = this.hkcblrDAO.getGlqList(map);//單位名稱list
		if("insert".equals(flag)){
			init();
		}else{
			map.put("id", id);
			ldzbmap = this.hkcblrDAO.getZygzlById(map);
		}
		return SUCCESS;		
	}

jsp:

<th>措施名稱</th>
<td align="left" >
	<select id="csmc" name="csmc" style="width:90%">
		<option value="">請選擇</option>
		<s:iterator value="%{csmcList}">					
                    <option value="${SBLB}" <s:if test="%{ldzbmap.CSMC==SBLB }">selected</s:if>>${SBLB}    </option>	
                </s:iterator>
	</select>
</td>