tags:

views:

3849

answers:

2

I am using the Struts iterator tag and trying to get 3 elements of my list in 1 iteration.

This is what I have.

<s:iterator status="stat" value="(secondResultSet.size()/3).{ #this}" >
   <s:property value="#stat.count" /> <!-- Note that "count" is 1-based, "index" is 0-based. -->
   <s:property value="%{secondResultSet.get(#stat.index).altId}"/>
   <s:property value="%{secondResultSet.get(#stat.index+1).altId}"/>
   <s:property value="%{secondResultSet.get(#stat.index+2).altId}"/>
</s:iterator>

my list has 18 elements and in a single iteration I want to print out 3 elements. Thats why I am dividing the length of list by 3. So loop will run 6 times...in total printing out 18 elements.

For this example different altId my list contains are: 41 - 58 (18). However, the code I have prints out the following

First Iteration: 41 42 43
Second Iteration: 42 43 44
Third Iteration: 43 44 45

So it seems like the counter is not getting updated. Can someone help me with this?

A: 

for someone else trying to do this...

Best way is to create the list in your class like so:

public void generateIteratorList()
{
    iterList = new ArrayList();
    int value = 0;
    for (int i = 0; i < (getSecondResultSet().size()/3); i++)
    {
        iterList.add(value);
        value+=3;
    }
}

and then use s:iterator tag like so:

<s:iterator status="stat" value="iterList" >
   <s:property value="%{secondResultSet.get(top).altId}" />
   <s:property value="%{secondResultSet.get(top+1).altId}" />
   <s:property value="%{secondResultSet.get(top+2).altId}" />
</s:iterator>
Omnipresent
A: 

I met this case when I used struts 2 :In the jsp page , i declared ... In the java , i declared private List listAssignmentUserBean; and methods getter(), setter() but when i get value of iterator back java page , result :listAssignmentUserBean= null Why? Please reply soon thanks so much

please post a new question with your sample code. Can someone with higher karma delete this ?
Omnipresent