Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break at some point in Struts2 Iterator

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.

like image 478
JR Galia Avatar asked Oct 26 '25 15:10

JR Galia


1 Answers

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>
like image 81
ramp Avatar answered Oct 29 '25 03:10

ramp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!