AnsweredAssumed Answered

How to break from a nested gel:forEach loop?

Question asked by StevenJames on Jun 27, 2012
Latest reply on Jun 28, 2012 by StevenJames
Hi all,
I have a <gel:forEach> loop nested within a <core:while> loop. I need to break out from the <gel:forEach> loop and continue round the <core:while> loop. If I use <core:break/> then I am taken out of the <core:while> loop rather than the <gel:forEach> loop. Has anybody come across a work around for this?
The code sample below demonstrates this issue:
<gel:script xmlns:core="jelly:core"
            xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
<gel:parse var="groups">
    <groups>
        <group code="CTU">CTU Team</group>
        <group code="SWAT">SWAT Team</group>
        <group code="ADMIN">Admin Team</group>
        <group code="DEV">Developer Team</group>
    </groups>
</gel:parse>

<core:set var="theTest" value="true"/>
<core:while test="${theTest == true}">
    <gel:forEach select="$groups/groups/group" var="group">
        <gel:set var="code" select="$group//@code" asString="true"/>
        <gel:out>${code}</gel:out>
        <core:if test="${code == 'ADMIN'}">
             <gel:set select="$groups/groups/group/@code" var="theTest" asString="true"/>
             <core:break/>
        </core:if>
    </gel:forEach>
    <gel:out>Out of forEach!</gel:out>
</core:while>
<gel:out>Out of while!</gel:out>
</gel:script>
Regards
Steve

Outcomes