如何在JSP上使用display标签显示嵌套数组列表? [英] How to show nested array lists using display tag on JSP?

查看:81
本文介绍了如何在JSP上使用display标签显示嵌套数组列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

每个员工都有分配清单.

Each employee has allocation list.

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.

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

每个员工将为每个类别具有相应的值.

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

员工erik的X = 10,Y = 20,Z = 67,依此类推.

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.

我不想使用display标记的嵌套表功能,该功能允许显示嵌套列表,因为嵌套列表未在Display标记中导出.

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.

推荐答案

好.所以我自己弄清楚了.下面是工作代码.

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>

这篇关于如何在JSP上使用display标签显示嵌套数组列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆