Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET] Break or continue for <c:iterate>
[JET] Break or continue for <c:iterate> [message #510037] Tue, 26 January 2010 10:16 Go to next message
Francis Gavino is currently offline Francis GavinoFriend
Messages: 57
Registered: July 2009
Member
Hi,

Is there a "break" or "continue" functionality in JET that can be used inside a <c:iterate> block? If no such tag exists, is there a workaround?

Thanks.
Francis
Re: [JET] Break or continue for <c:iterate> [message #510169 is a reply to message #510037] Tue, 26 January 2010 15:43 Go to previous message
Paul Elder is currently offline Paul ElderFriend
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
Previous Topic:[xpand] dynamic expansion of template
Next Topic:[xtend] Couldn't find operation 'setName(type::String)' for type 'cakefeed::BFBType'
Goto Forum:
  


Current Time: Fri Apr 26 07:24:47 GMT 2024

Powered by FUDForum. Page generated in 0.04252 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top