2012-03-16 10 views
2

안녕하세요 여러분에게 돌아 오는 bean이 있고 bean의 속성 중 하나가 다른 bean의 배열입니다.JSTL의 루프 배열

루핑하는 동안 다른 속성을 잘 표시하고 jsp에 표시 할 수 있지만 내 배열의 내용을 가져와야합니다. 나는 그것을 잘못하고있는 것을 알고 있으며 그 문법이 무엇인지를 잊어 버렸다.

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 클래스의 메신저 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; } 

역할에 걸쳐 반복하는 것은 또 다른 콩과의 게터는 getName()getId()입니다

나는해야한다. 마지막 열에 아이디의 배열을 diaply하지만 임은 메모리 위치를 점점 ...

답변

5

당신은뿐만 아니라

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

당신의 역할을 통해 루프에 필요한 또 다른 가능성은

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

입니다 첫 번째 역할 만 찾고 있다면.

+0

안녕하세요, 고맙습니다. 나는 과장 생각했습니다. 많이 감사합니다. –