0

I have my code like this

ResourceDetailsBean.java

public String empName;
public String empCode;
public LinkedHashMap<String, List<ResourceBandBean>> backFillPlanGAP;

ResourceBandBean.java

private String band;
private String name;

At the end of my code, generating a list of first bean type.

My Action class and DAO Logic is correct. Can someone please guide me how to display it on JSP.

I am using something like this..

<table><thead>
    <th>Emp Name</th>
    <th>Code</th>
    <th>band1</th>  
    <th>band2</th> <!--These bands are same as String Key in LinkedHashMap, Number of keys will be equal to number of band header -->
    <th>band3</th></thead>
     <tbody>
    <s:iterator value="resourceList">
      <tr>
        <td><s:property value="empName"/> </td>
        <td><s:property value="empCode"/> </td>
        <s:iterator value="backFillPlanGAP" status="stat">
          <td><s:property value="#backFillPlanGAP[1]"/></td>
        </s:iterator>
</tr></tbody>

backFillPlanGAP is the name of LinkedHashMap.

How to display these value in a proper tabular format?

Kindly guide me, I am not able to parse them. Let me know if clarification needed on any part.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Crawling
  • 87
  • 11

2 Answers2

0

Try with JSTL Core Tag Library .

The variable used in outer loop will become the input of inner loop.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core prefix="c"%>

<table border="1">
    <thead>
        <tr>
            <th>Emp Name
            <th>Code</th>
            <th>band1</th>
            <th>band2</th>
            <th>band3</th>
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${resourceList}" var="each">
            <tr>
                <td>${each.empName}</td>
                <td>${each.empCode}</td>
                <c:forEach items="${each.backFillPlanGAP}" var="entry">
                    <c:forEach items="${entry.value}" var="list">
                        <td>${list.band}</td>
                    </c:forEach>
                </c:forEach>
            </tr>
        </c:forEach>
    </tbody>
</table>

You can do in this way as well ${each.getEmpName()} or ${each['empName']} instead of ${each.empName}

Note: Each POJO class has getter and setter methods for instance members to access in JSP.

Braj
  • 46,415
  • 5
  • 60
  • 76
0

You can iterate a List inside a Map as follows:

<s:iterator value="backFillPlanGAP">
<tr>
    <td>Key: <s:property value="key" /></td>
    <td>Value(s):
        <table>          
            <tr> 
            <s:iterator value="value" var="currentItem">
                <td>
                    <s:property value="currentItem"/>
                </td>
            </s:iterator>
            </tr>
        </table>
    </td>                
</tr>
</s:iterator>
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243