我现在有两个集合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对象就没有显示出来
[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对象就没有显示出来
解决方案 »
- mybatis配置po的XML文件的时候标签不自动出来
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).错误
- 文件上传的进一步思考.
- 请struts2.0的最大特点是什么
- 为什么login()这个js无效呢
- JSP中的格式必须要有<html><head></head><body></body></html>吗?我看到有地方没写这些,在线等!
- 问一个简单却怎么也找不到解决办法的问题。对我而言颇有点难度,求助,谢谢!
- Js问题:如何控制多个层的树
- 我的网站最近上传了。。。朋友们去看看!!
- 麻烦小事情,关于javabean的路径问题
- java网络编程疑问,高手进
- java applet读取摄像头问题
只用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>
<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>
<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,但是不同的呢?你写到哪里去了?