我现在有两个集合List<Functionlist> allFunctions 和List<Functionlist>personnelFunctions,现在要在前台的JSP页面上面把所有的allFunctions集合里面的Functionlist对象的name属性给显示出来,然后在每一个name前面加上一个复选框,这个复选框的选中的条件是,如果allFunctions里面的某一个对象的name属性和personnelFunctions里面的某一个对象属性相同,此复选框就选中,allFunctions 和 personnelFunctions的关系是,personnelFunctions都是allFunctions的子类。
[code=JSP]
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr class="tableHeard">
<th width="10%">选中</th>
<th width="90%" class="textAlignLeft">权限名称</th>
</tr>
</tbody>
<c:forEach items="${allFunctions}" var="function">
<tr>
<c:forEach items="${personnelfunctions}" var="myfunction">
<c:if test="${myfunction.name == function.name}">
<td><input name="checkbox" type="checkbox"
value="${function.id}" checked="checked" /></td>
<td class="textAlignLeft color999">${function.name }</td>
</c:if>
</c:forEach>
</tr>
</c:forEach>
</table>
[/code]我现在是这么写的,但是这么写就只能显示出personnelfunctions里面的Functionlist对象,并且每一个都勾选住,但是allFunctions中的其他没有在personnelfunctions存在的Functionlist对象就没有显示出来

解决方案 »

  1.   


    只用if当然不会实现你要的效果,它只是执行符合条件的,不符合条件的它不会输出的
    <c:forEach items="${allFunctions}" var="function"> 
    <tr> 
    <c:forEach items="${personnelfunctions}" var="myfunction"> 
     <c:choose>
       <c:when test="${myfunction.name == function.name}"> 
    <td> <input name="checkbox" type="checkbox" 
                 value="${function.id}" checked="checked" /> </td>           
       </c:when>
      <c:otherwise>
    <td> <input name="checkbox" type="checkbox" 
                 value="${function.id}"  /> </td>      
       </c:otherwise>
    </c:choose>
    </c:forEach> 
    </tr> 
    </c:forEach> 
      

  2.   

    这样写的话会在第二个Foreach循环很多次,显示出来的结果也是不对的
      

  3.   

    刚才没有仔细看,仔细看了下,你这个问题我以前做过这样权限的问题,我在后台中 一共用了三个list,list3中封装了listtt和listnon,listtt和lsitnon里面的数据分别是选中和未选中的,
    <c:forEach var="list3" items="${requestScope.hlistyou}" >
    <span class="tablestyle_title"> <input type="hidden" name="levelid" value="${list3.id }"/>  ${list3.name }</span><br/> <br/> 
     <c:forEach var="listt" items="${list3.list}">
         <input type="checkbox" checked="checked" name="role${list3.id}" value="${listt.id }"/> ${listt.levelName }
           </c:forEach>
    <c:forEach var="non" items="${list3.listnon}">
     <input type="checkbox" name="role${list3.id}" value="${non.id }"/> ${non.levelName }
    </c:forEach>
      <br/> <br/>
    </c:forEach>
      

  4.   


    <c:if test="${myfunction.name == function.name}"> 
    <td> <input name="checkbox" type="checkbox" 
    value="${function.id}" checked="checked" /> </td> 
    <td class="textAlignLeft color999">${function.name } </td> 
    </c:if> 
    看你的代码。name相同的话就会有个checkbox,但是不同的呢?你写到哪里去了? 
      

  5.   

    想了想,好像jstl无法实现,楼主转变思路,返回json用js去处理吧。=。=
      

  6.   

    错了,LZ别信,假如是lId的话就会有问题=。=小激动了