tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikola Milutinovic <alok...@yahoo.com>
Subject Re: c:forEach not working as expected
Date Tue, 14 Feb 2006 14:45:20 GMT
--- Reinhard Moosauer <rm@moosauer.de> wrote:

> Hi List,
> 
> it seemed clear to me, that this construct:
> 
>   <c:forEach items="${t.records}" var="x">
>      ... (some inner logic)
>   </c:forEach>
>  
> should be equivalent to this one:

No. It is roughly equvalent to (see my corrections):

>   <%
>   for (Iterator it=t.getRecords(); it.hasNext(); ) {

    for (Iterator it=t.getRecords().getIterator(); it.hasNext(); ) {

>      String x = (String)it.next();

       Object x = it.next();

>   %>
>      ... (some inner logic)
>   <% }
>   %>

I said roughly, because it can handle arrays, too.

> But the forEach-version is not working as expected. What can be wrong?
> Here are some quite strange effects:
> 1. The iterators-method "hasNext()" is called twice for every iteration
>     (ok: no problem, if the iterator is clean, but why?)

This is normal. Try to locate the java code generated from that tag and see
what it comes to. You'll see something educational. There is no "while ()"
loop. Just "if () else" logic.

> 2. The loop-body is executed after hasNext() returned false.
>     But the next()-method is NOT called ??

That would be strange.

Nix.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message