2012-03-16 10 views
2

私は戻ってきたBeanを持っていて、Beanのプロパティの1つは別のBeanの配列です。JSTLのループオーバー

私は他のプロパティをうまく使い果たし、ループ中にjspに表示できますが、配列の内容を取り出す必要があります。私はそれを間違ってやっていることを知っていて、構文が何かのために何かを忘れています。

私は最終的に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> 

豆: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クラスイムは役割が別のBeanであり、そのゲッターがgetName()getId()です

私は最後の列にIDの配列をdiaplyが、イムだけでメモリ位置を取得...

答えて

5

はあなたにも

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

あなたの役割をループに必要なもう一つの可能​​性は

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

ですあなたが最初の役割だけを探しているならば。

+0

こんにちは、ありがとうございました。 –