2012-03-16 125 views
0

再次匹配。基本上我在用户浏览页面时检查角色。它的一个数组,可以说1,2,3。用于测试的jsp上最后一列的内容具有附加到每个单独附件的角色#。最后一栏不会是在成品上,但我需要做某种IF该阵列上,看是否有数组中的值:JSTL检查一个数组中的值是否与第二个数组

<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需要精确匹配的阵列,只是用户角色的所述阵列中的值是固定角色的阵列中....

我需要在这里做检查,以determin是否把一个禁止标志上的“删除”按钮:

<rbac:check operation="<%=Operation.DELETE%>"> 
         <button type="button" onclick="javascript:delete_prompt(${item.id});">Delete</button> 
        </rbac:check> 
         </td> 
        <td> 
+0

即时通讯思想也许2嵌套的循环 – 2012-03-16 14:55:37

+0

'' – 2012-03-16 14:55:53

+0

不确定... ..... – 2012-03-16 14:56:23

回答

1

做2嵌套的循环和具有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> 
2

创建自定义EL函数(这应是一个类的静态方法,并在您的TLD文件中提供正确的描述符)。例如具有签名boolean contains(Collection collection, Object object)的方法。然后调用它作为<c:if test="x:contains(list, object)">

+0

感谢您的建议.....但我创建的嵌套for循环似乎工作.... – 2012-03-16 15:40:49

+0

我知道它可以工作,但将逻辑(即使是这种情况)从JSP中移出要好得多。 – 2012-03-17 04:28:06

相关问题