Shawn gave a great answer to this question before:
In the future please search the archives first.

Shawn's response:

"New tags would be required for this, but they are not implementable in JSP
1.2 and have thus are not planned for JSPTL 1.0.

The problem is how a <break> tag would signal the completion of a loop and
cause the loop to terminate immediately.  <break> could be implemented
merely as a 'signal' to the containing <forEach> tag to halt iteration
after the current round of iteration, but this would not be a true break
and would be confusing because of its differences with Java's 'break'
keyword.

<break> could be implemented better if it threw an exception meant to be
caught using JSP 1.2's TryCatchFinally interface, but the implementation
would still not be fully operable when custom tags were involved.  In a
situation like

   <forEach>
     <custom tag>
        <break/>
     </custom tag>
   </forEach>

the handler for <custom tag> would, if it implemented TryCatchFinally,
need to know to re-throw the exception that the inner <break> tag throws.  
If it didn't, then <break>'s message would be lost and it would have no
effect.  A <break> tag that we couldn't guarantee to work wouldn't be much
of a <break> tag!

<Continue> is even more problematic, since the TryCatchFinally
implementation would be completely untenable:  once an exception is caught
by doCatch(), there is no mechanism to "restart" the tag.

Thus, <break> and <continue> are not planned as JSPTL tags, at least not
in JSPTL 1.0.  You can emulate their behavior with proper structuring of
<if> tags.  While more verbose, this latter usage is more closely in line
with what's seen as a more typical JSP pattern:  JSP, being used mostly
for presentation, needs less intricate control flow than the Java language
itself provides.

Shawn Bayern
JSPTL reference-implementation lead"


-----Original Message-----
From: MARCIO JULI�O [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 03, 2003 10:40 AM
To: Tag Libraries Users List
Subject: tag forEach


Hi,

        Is there a way to break the flow inside the tag forEach ?

Example:

<c:forEach items="${listaDatas}" var="data" varStatus="contador">
        ...
        <c:if test="${data.dia == 31}">
                <break/>
        </c:if>
</c:forEach>

M�rcio Juli�o
RiskControl Servi�os Ltda.
Email:[EMAIL PROTECTED]
Tel: (21) 2514-8253
Fax: (21) 2514-8233
Acesse o site: http://www.riskcontrol.com.br

-------------------------------------------------------------------------
Esta mensagem cont�m informa��es confidenciais e foi enviada somente ao(s)
destinat�rio(s) acima. Caso voc� n�o seja a pessoa endere�ada, n�o dever�
divulgar, distribuir ou copiar esta mensagem. Se voc� a recebeu por engano,
favor notificar imediatamente o remetente e em seguida destru�-la.
                 
This message contains confidential information and is intended only for the
individual named. If you are not the addressee you should not disseminate,
distribute or copy this message. Please notify the sender immediately if you
have received this message by mistake and then destroy it. 
------------------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to