java
  • jsp
  • jstl
  • 2012-03-16 79 views 2 likes 
    2

    嘿傢伙我有一個bean返回,其中一個屬性是另一個bean的數組。循環豆陣列在JSTL

    我可以讓我的其他屬性很好,並顯示在jsp while循環,但我需要得到我的數組的內容了。我知道我做錯了,忘記了這樣的語法是什麼。

    Baaically我需要role.id在最後一欄。這是我的了:

    JSP:

    <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>${item.roles}</td> 
    
           </tr> 
          </c:forEach> 
         </c:otherwise> 
        </c:choose> 
        </table> 
    

    豆:

    Bean類的IM在items="${attachList}"

    private long id; 
    private String fileName; 
    private String fileType; 
    private int fileSize; 
    private Role[] roles; 
    private AuditableBean auditable; 
    
    /** 
    * Constructor. 
    */ 
    public AttachmentShortBean() 
    { 
    } 
    
    public long getId() { return id; } 
    
    public String getFileName() { return fileName; } 
    
    public String getFileType() { return fileType; } 
    
    public int getFileSize() { return fileSize; } 
    
    public Role[] getRoles() { return roles; } 
    
    public AuditableBean getAuditable() { return auditable; } 
    

    角色遍歷是另一個bean及其干將是getName()getId()

    我需要diaply ID的陣列中的最後一列,但我只是得到一個內存位置...

    回答

    5

    你需要循環在你的角色以及

    <c:forEach items = "${item.roles}" var = "role"> 
        <c:out value = "${role.id}"/> 
    </c:forEach> 
    

    另一種可能性是

    <c:out value = "${item.roles[0].id}"/> 
    

    如果你只是在尋找第一個角色。

    +0

    嘿謝謝你,我想我是過度思考.....非常感謝 – 2012-03-16 12:46:40

    相關問題