On 2/13/06, Reinhard Moosauer <[EMAIL PROTECTED]> 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: > > <% > for (Iterator it=t.getRecords(); it.hasNext(); ) { > String x = (String)it.next(); > %> > ... (some inner logic) > <% } > %> > > 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?) > 2. The loop-body is executed after hasNext() returned false. > But the next()-method is NOT called ?? > > The c:forEach-iterator seems to operate like this: > > Iterator it = t.getRecords(); > while (it.hasNext()) { > String x = (String)it.next(); > boolean still_more = it.hasNext(); > > ... here comes the body ... > } > > What could this extra-check be good for? > > Any help is greatly appreciated. > Kind regards, > > Reinhard > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
It has to do with the way the iteration code is divided between the <c:forEach> and </c:forEach> tags. I'm not sure if it *had* to be done that way; you can dig into the Tomcat and JSTL source if you want to redesign it. ;-) -- Len --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]