How to show nested array lists using display tag o

2019-05-20 08:12发布

I have two array lists. Employee List and Allocation List.

Each employee has allocation list.

Employee class is as follows.

public class Employee {

    private int id;   
    private String firstname;

    private String lastname;

    private List<Allocation> allocationList ; 

    // geters and setters

}

and Allocation class is as follows

public class Allocation {

    private int categoryId;

    private String categoryName;

    private float allocation;

    // getters and setters

}

Lets say we have three allocation categories named X, Y and Z.

Each employee will have corresponding values for each of these categories.

Employee erik has X= 10, Y = 20 and Z = 67 and so on.

How do show employee details as well as these allocation per employee as shown in the figure below using display tag.

enter image description here

I do not want to use the nested table feature of display tag which allows to show nested lists as the nested lists are not exported in Display tag.

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-20 09:06

Ok. So I figured it out myself. Below is the working code.

<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>
查看更多
登录 后发表回答