IF
来查看数组中是否有任何值:
<c:forEach items = "${hotPartRoles}" var = "hpRole">
${hpRole.id}
</c:forEach>
位于附件角色的数组中:
<c:forEach items = "${item.roles}" var = "role">
${role.id}
</c:forEach>
JSP:
<table class="data_table">
<tr>
<th>Attachments</th>
//These are the user's Roles
<c:forEach items = "${hotPartRoles}" var = "hpRole">
${hpRole.id}
</c:forEach>
</tr>
<tr>
<td class="subtable">
<table class="data_table">
<c:choose>
<c:when test='${empty attachList}'>
<tr>
<td>No Attachments</td>
</tr>
</c:when>
<c:otherwise>
<tr>
<th>Remove Attachment</th>
<th>File Name</th>
<th>File Type</th>
<th>File Size (bytes)</th>
<th>File Attached By</th>
<th>Date/Time File Attached</th>
<th>Roles</th>
</tr>
<c:forEach var="item" items="${attachList}" varStatus="loopCount">
<tr>
<td class="button">
<rbac:check operation="<%=Operation.DELETE%>">
<button type="button" onclick="javascript:delete_prompt(${item.id});">Delete</button>
</rbac:check>
</td>
<td><a href="show.view_hotpart_attachment?id=${item.id}">${item.fileName}</a></td>
<td>${item.fileType}</td>
<td><fmt:formatNumber value="${item.fileSize}" /></td>
<td>${item.auditable.createdBy.lastName}, ${item.auditable.createdBy.firstName}</td>
<td><fmt:formatDate value="${item.auditable.createdDate}" pattern="${date_time_pattern}" /></td>
<td>
<c:forEach items = "${item.roles}" var = "role">
${role.id}
</c:forEach>
</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
现在数组ont需要完全匹配,只是用户角色数组中的值在附件角色数组中....
我需要在这里检查以确定是否在“删除”按钮上放置禁用标志:
<rbac:check operation="<%=Operation.DELETE%>">
<button type="button" onclick="javascript:delete_prompt(${item.id});">Delete</button>
</rbac:check>
</td>
<td>
答案 0 :(得分:2)
创建自定义EL函数(它应该是类中的静态方法,以及TLD文件中的正确描述符)。例如,签名为boolean contains(Collection collection, Object object)
的方法。然后将其称为<c:if test="x:contains(list, object)">
答案 1 :(得分:1)
首先执行2个嵌套for循环并将var设置为false,然后设置为true并检查该var似乎有效
<c:forEach var="item" items="${attachList}" varStatus="loopCount">
<c:set var="dispVal" value="false"/>
<c:forEach items = "${item.roles}" var = "role">
<c:forEach items = "${hotPartRoles}" var = "hpRole">
<c:if test="${hpRole.id == role.id}">
<c:set var="dispVal" value="true"/>
</c:if>
</c:forEach>
</c:forEach>
<tr>
<td class="button">
<rbac:check operation="<%=Operation.DELETE%>">
<button type="button"<c:if test="${dispVal != 'true'}"> disabled="disabled"</c:if>
onclick="javascript:delete_prompt(${item.id});">Delete</button>