Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logic:iterate How to break the loop for a certain value in collection

 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
i have a collection(IDRequirements) of size 12 that i am iterating. What i am trying to do is to break this collection into multiples of 4 and show it in three different columns of a table. As you can see from the code below i am having all of them displayed in one column of a table.

I am wondering if there is some way to set this offset value in logic:iterate so that i can dynamically generate a columns with 4 check boxes in each(In my case). I do not want to reinvent wheel by writing my own tab library to do this if something like this can be done using Struts tags someway.

Guys Appreciate your help.


<td height="24" width="25%" class="odd">

<logic:iterate id="IDRequirement" name="InitialPageDetailViewBean" property="IDRequirements">


<html:multibox property="IDRequiredValues">
<bean:write name="IDRequirement" property="value"/>
</html:multibox>
<bean:write name="IDRequirement" property="label"/><br/>
</logic:iterate>

</td>
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works pretty well... unless you've a bad case of scriptletphobia.

<td height="24" width="25%" class="odd">
<% int count = 0; %>
<logic:iterate id="IDRequirement" name="InitialPageDetailViewBean" property="IDRequirements">
<% if(count++ % 4 == 0){ %>
</td>
<td height="24" width="25%" class="odd">
<% } %>
<html:multibox property="IDRequiredValues">
<bean:write name="IDRequirement" property="value"/>
</html:multibox>
<bean:write name="IDRequirement" property="label"/><br/>


</logic:iterate>

</td>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic