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。
一.下拉列表的集合已知:
<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。
相关文章推荐
- Spring form标签 Select 根据后台传值 动态选中
- jQuery根据文本设置select选中失效问题
- Select标签 根据value值默认选中 Jquery
- IE8下Jquery获取select选中的值post到后台报错问题
- 前台根据后台值 操作字段 显示或select选中状态
- 使用select2.js 时 根据val和text选中问题
- select标签以及默认选中当前分类问题
- asp.net 后台根据数据库中的值 利用js给select标签赋选中值
- 开发日志:<s:select>标签显示从后台传过来的空格问题
- Select标签 根据value值默认选中 Jquery
- 标签 select根据request参数自动选中某个数值
- Jquery根据后台数居设置select。radio,checkbox选中
- 后台传参与select-option标签的默认选中
- select根据后台值选中
- JavaScript_JavaEE__让 select标签 根据后台传入的数据选择默认值
- jsp中select标签解决默认选中问题
- IE8下Jquery获取select选中的值post到后台报错问题
- 用Jquery根据获取的value来设置select标签的默认选中项
- select标签根据text或者value选中
- struts2的 select标签选中问题解决