Search code examples
javaapache-poijxls

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>

Solution

  • 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}">