2012-03-16 49 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

相關問題