tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@swapsimple.com
Subject Re: Break a forEach loop
Date Thu, 15 Dec 2005 08:35:28 GMT
On Tue, Dec 13, 2005 at 11:02:02AM +0100, Rolf Niepraschk wrote:
> can you tell me if it is possible to break a simple forEach loop
> premature. The following doesn't work:
> 
> <c:forEach begin="1" end="30" varStatus="status">
>   ${status.count}<br>
>   <c:if test="${status.count==10}">
>     <c:set var="status.count" value="31" />
>   </c:if>
> </c:forEach>

	that's because the status variable is read-only.  It has no setCount()
method.
	The easiest way, if you really can't find anyway around it, which
will probably work, is just:
<% break; %>

	but the best way is probably to re-write your loop so you don't
need to do this.

	Alternately, you could write a custom tag that uses
findAncestorWithClass() to grab the LoopTagSupport object (i.e. the
c:forEach tag object) and try using introspection to set the "end"
property.  (or make the specific to apache taglibs and cast it to
a org.apache....ForEachTag object and call setEnd() directly)

eric

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message