|
Re: [JET] Break or continue for <c:iterate> [message #510169 is a reply to message #510037] |
Tue, 26 January 2010 15:43 |
Paul Elder Messages: 849 Registered: July 2009 |
Senior Member |
|
|
Francis:
There is no break/continue semantics. To be honest, I hadn't thought about it before.
Here are some work-around ideas:
For 'continue', I could imagine a code flow something like:
<c:iterate ... >
<c:if test="...">
<c:continue/> <%-- an imaginary continue tag --%>
</c:if>
... rest of iterate block
</c:iterate>
You could re-formulate this (without the imaginary c:continue tag) as follows:
<c:iterate ... >
<c:if test="not(...)">
... rest of iterate block
</c:if>
</c:iterate>
For 'break', I can imagine a similar c:break tag:
<c:iterate ...>
... start body of iterate
<c:if test="...">
<c:break/> <%-- an imaginary break tag --%>
</c:if>
... rest of iterate block
</c:iterate>
Again, I could reformulate this using current tags, plus a JET variable:
<c:setVariable var="inBreak" select="false()"/>
<c:iterate ... >
<c:if test="not($inBreak)">
... start body of iterate
<c:if test="...">
<c:setVariable var="inBreak" select="true()"/>
<%-- it's time to break -- %>
</c:if>
<c:if test="not($inBreak)" >
... rest of iterate block
</c:if>
</c:if>
</c:iterate>
The reason for the double set of c:if tags is that there is no way to stop the c:iterate tag, so the best that can be done is to stop it from rendering any more text. Also, the c:iterate tag's 'select' statement is evaluated only once, so it's no good trying to test $inBreak in that expression - it will always be false().
Finally, some initial thoughts on how such tags could be created.... Both 'break' and 'continue' imply a jump, similar to a 'throw' statement. Unfortunately, the JET tag infrastructure doesn't anticipate such things. It would be cool to have a c:break or c:continue tag implementations simply throw an exception that the c:iterate tag handler would then catch. You could write such code now, but JET currently catches the exceptions and converts them to log messages in the originating tag handler - you wouldn't get the desired results.
Let me know if you think such tags would be useful. There still may be room to get it into the Helios release, if I can figure something out.
Paul
|
|
|
Powered by
FUDForum. Page generated in 0.02869 seconds