I have nested iteration in Struts2:
<s:iterator var="gift" value="user.gift">
<s:iterator value="giftItems">
<s:property value="type"/>
</s:iterator>
</s:iterator>
I want to have up to 10 type only. How to break at some point in Struts2 Iteration? I can have a counter variable, but don't know to break in iteration.
Thanks.
You could use the begin and end attributes if you know when to break out before begining the iteration. If the break has to be calculated within the iteration, set a variable and check its value using each time before doing the iteration. In the later case, the loop will technically not 'break', but the effect would be the same.
<s:set var = "breakLoop" value = "%{false}" />
<s:iterator....>
<s:if test = "!#breakLoop">
//process here and change the var to true based on some codition
<s:set var = "breakLoop" value = "%{true}"/>
</s:if>
</s:iterator>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With