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

分两种情况:
一.下拉列表的集合已知:
     <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。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值