shreyansh jogi
shreyansh jogi

Reputation: 2102

Struts2 iterator display

I am using Struts2 iterator tag to display value in JSP.

having list called DepotList

iterating using following code

<s:iterator value="depotList" var="product" status="incr">
  <tr>
     <td><s:property value="depotDescription" /></td>
     <td>0</td>
  </tr>
</s:iterator>

it display like below

Depot1  0
Depot2  0
Depot3  0
15511   0

but I want to display below manner

Depot1 0      Depot2 0
Depot3 0      15511  0

Any idea how to iterate loop to get out put like this?

Upvotes: 1

Views: 1301

Answers (3)

PbxMan
PbxMan

Reputation: 7623

You could use the count property instead of odd/even for 2 or more columns. In the following example would be for 3(module), adjust accordingly.

    <s:iterator value="depotList" var="product" status="incr">

   <s:if test="#incr.count%3 == 0 ">
     <tr>
   </s:if>

     <td><s:property value="depotDescription" /></td>
     <td>0</td>

   <s:if test="#incr.count%3 == 0 ">
     </tr>
   </s:if>
</s:iterator>

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240948

You want to goto new table row if it is odd iteration, try something like

<s:iterator value="depotList" var="product" status="incr">

   <s:if test="#rowstatus.odd == true">
     <tr>
   </s:if>

     <td><s:property value="depotDescription" /></td>
     <td>0</td>

   <s:if test="#rowstatus.odd == true">
     </tr>
   </s:if>
</s:iterator>

Upvotes: 0

Jwalin Shah
Jwalin Shah

Reputation: 2521

It's not problem of iteration. But you can manage it by div based layout with css.

Upvotes: 0

Related Questions