您的位置:首页 > 其它

select标签根据后台值选中问题

2014-06-30 18:58 302 查看
分两种情况:

一.下拉列表的集合已知:

<td class="inputword">字典类别:</td>

<td align="left">

<select id="selectType" name="dictionaryType">

<c:if test="${dic.dictionaryType=='sys'}">

<option value="sys" selected="selected">系统</option>

<option value="user" >用户</option>

</c:if>

<c:if test="${dic.dictionaryType=='user'}" >

<option value="sys" >系统</option>

<option value="user" selected="selected" >用户</option>

</c:if>

</select></td>

二.下拉列表的集合从后台传过来:

.........java code(spring mvc --controller)..........

List<IProductLine> productList=new ArrayList<IProductLine>();

IProductLine productline=new IProductLine();

dic=dicService.get(hql, param);

productline.setProductId(dic.getIProductLine().getProductId());

productline.setProductCode(dic.getProductCode());

productline.setProductName(dic.getIProductLine().getProductName());

productList=productService.find(hql2, param);

model.addAttribute("productList", productList);

model.addAttribute("productline", productline);

.........java code(spring mvc --controller)..........

.........jsp code..........

<td class="inputword">所属产品线:</td>

<td align="left">

<c:set var="productline" value="${productline}" />

<select name="productId">

<c:forEach var="list" items="${productList}">

<c:choose>

<c:when test="${productline.productId==list.productId}">

<option selected="selected" value="<c:out value="${list.productId}"/>">

<c:out value="${list.productName}"/>

</option>

</c:when>

<c:otherwise>

<option value="<c:out value="${list.productId}"/>">

<c:out value="${list.productName}"/>

</option>

</c:otherwise>

</c:choose>

</c:forEach>

</select>

</td>

.........jsp code..........

checkbox和select比较类似:

用<c:set var="productline" value="${productline}" />将要编辑的对象放到前台(其实是放到了request里)。然后用<c:forEach将要显示成checkbox的集合遍历,跟要编辑的对象的属性对比,如果该属性和集合的对象的属性一样,就selected。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: