Barry
Barry

Reputation: 1820

s:iterator test if at certain iteration

I have searched around and cannot find an answer.

Say I have a list in session of 5 items in session. How do I tell if I am at a certain iteration in the loop of s:iterator? For example say list is [a,b,c,e,f] and I want to iterate through list and print a,b,c, then inject/print d, then print e f so on the page it looks like the list is a b c d e f.

I have been trying this:

<s:iterator value="example" status="stat">
<s:if test="#stat.count == '3'">
    inject d...
</s:if>
<s:else>
    s:property tag to print values
</s:else>
</s:iterator>

Upvotes: 0

Views: 7120

Answers (1)

Dustin Wilhelmi
Dustin Wilhelmi

Reputation: 1819

The status attribute you are looking for is "index", not "count". Also, I didn't know if it was a typo in the code or just in your post, but your status="stat" attribute has the equals sign inside the quotes. Try this instead:

<s:iterator value="example" status="stat">
<s:if test="#stat.index == '3'">
    inject d...
</s:if>
<s:else>
    s:property tag to print values
</s:else>

Upvotes: 4

Related Questions