1

I have an arrayList which has objects of a bean within it. In the view, I am iterating and printing the list using <c:foreach> tag.

I am printing this list into a table, so I need to print 4 elements of a list at time inside of a <tr> tag. Then the next 4 elements in another <tr>, so on.

How would I do that? Is there an index to use so that I can store the value and only start from there the next time I iterate the list?

E.g. of my hypothesis:

<for i=list.length i++>
{
   <tr>
       <td>${ListElement}</td>
   </tr>
}
2
  • Please post the code you used Commented Nov 11, 2012 at 4:19
  • There is no code yet. I am planning the code still Commented Nov 11, 2012 at 4:21

3 Answers 3

1
 <s:iterator var="listVar" value="%{ListElement}" status="entryStatus">
     <s:property value="#entryStatus.count"/> <!-- start's from 0 -->
     <s:property value="#entryStatus.index"/> <!-- start's from 1 -->
     <s:property value="%{ListElement[#entryStatus.index].yourBeanPropertyName}"/>
     <s:property value="%{#listVar[#entryStatus.index].yourBeanPropertyName}"/>
 </s:iterator>
Sign up to request clarification or add additional context in comments.

Comments

0

Use <s:iterator> tag with begin, end and status attributes http://struts.apache.org/2.x/docs/iterator.html.

Comments

0

I used the tag along with finding multiples of number of rows. algorithm for code:

<c:foreach varStatus=x items=beanObject>
  if(x.index / 4 == 0)
{
  NEW ROW
}

</c:foreach>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.