sunleo
sunleo

Reputation: 10943

Iterate Map in JXLS and Apache POI template

I would like to know is this possible to iterate map in JXLS.I tried with examples given in Link, but I couldn't find way to iterate map.Please help me to find the solution.

Sample Code in XLSX template:

bomItemList-- List which has Event Objects. supplierResponse-- Map of SupplierResponse Objects.

  <jx:forEach items="${bomItemList}" var="eventItemList" varStatus="status">
      <jx:forEach items="${eventItemList.supplierResponse}" var="supplierResponse" select="${supplierResponse.key > user}">
                    ${supplierResponse.supplierqty} 
      </jx:forEach>
  </jx:forEach>

Output :(Inner forEach)

<jx:forEach items="{supplier2=com.esource.vo.Supplierresponse@1489519, supplier1=com.esource.vo.Supplierresponse@34ca1a}" var="supplierResponse" select="false">

  </jx:forEach>

Upvotes: 0

Views: 5535

Answers (2)

Nagasubramaniyan
Nagasubramaniyan

Reputation: 21

I use keySet() to iterate over map.

<jx:forEach items="${myMap.keySet()}" var="key1">
${myMap.get(key1).attr1}
</jx:forEach>

Upvotes: 2

rgettman
rgettman

Reputation: 178253

You can't iterate the Map directly, but you can iterate over the Collection of values that the map can supply. Call the values() method on the Map, which will return a Collection view of teh values that is suitable for iteration in JXLS.

<jx:forEach items="${eventItemList.supplierResponse.values()}" var="supplierResponse"
    select="${supplierResponse.key > user}">

Upvotes: 2

Related Questions