如何在JSP上使用display标签显示嵌套数组列表?

时间:2012-07-06 08:17:49

标签: jsp displaytag

我有两个数组列表。员工清单和分配清单。

每位员工都有分配清单。

Employee课程如下。

public class Employee {

    private int id;   
    private String firstname;

    private String lastname;

    private List<Allocation> allocationList ; 

    // geters and setters

}

Allocation类如下

public class Allocation {

    private int categoryId;

    private String categoryName;

    private float allocation;

    // getters and setters

}

假设我们有三个名为X,Y和Z的分配类别。

每位员工都会为每个类别提供相应的值。

员工erik有X = 10,Y = 20和Z = 67,依此类推。

如何使用display tag显示员工详细信息以及每位员工的这些分配,如下图所示。

enter image description here

我不想使用display tag的嵌套表功能,它允许显示嵌套列表,因为嵌套列表不会在Display标记中导出。

1 个答案:

答案 0 :(得分:3)

确定。所以我自己弄清楚了。以下是工作代码。

<display:table name="employeeList" pagesize="25" class="listingTable" keepStatus="true" cellpadding="0px"
  cellspacing="0px" id="employee" export="true" requestURI="">
  <display:setProperty name="export.decorated" value="true" />
  <display:setProperty name="export.excel.filename" value="${exportFileName}.xls" />

  <c:forEach var="cl" items="${selectedColumnList}">
    <display:column property="${cl.property}" title="${cl.title}" format="${cl.format}" />
  </c:forEach>

  <c:forEach var="allocationCl" items="${allocationCategoryList}" varStatus="status">
    <c:set var="allocationCounter" value="${status.index}" />
    <display:column title="${allocationCl.category}">
      <c:choose>
        <c:when test="${fn:length(employee.allocations) ne '0' }">
      ${employee.allocations[allocationCounter].allocation}
    </c:when>
        <c:otherwise>
      0
    </c:otherwise>
      </c:choose>
    </display:column>
  </c:forEach>

  <display:setProperty name="paging.banner.item_name" value="Employee" />
  <display:setProperty name="paging.banner.items_name" value="Employees" />
</display:table>