【问题标题】:How to show nested array lists using display tag on JSP?如何在 JSP 上使用显示标签显示嵌套数组列表?
【发布时间】:2012-07-06 08:17:49
【问题描述】:

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

每个员工都有分配清单。

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 等等。

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

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

【问题讨论】:

  • 这可以在显示标签中做到这一点还是我必须找到其他一些方法来做到这一点?我正在使用显示标签,因为我需要使用显示标签的导出功能。否则我必须手动进行导出。请帮忙。

标签: jsp displaytag


【解决方案1】:

好的。所以我自己想通了。下面是工作代码。

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 2012-09-12
    • 2021-12-14
    • 1970-01-01
    • 2012-07-07
    • 2019-07-11
    • 2013-08-02
    相关资源
    最近更新 更多