Mark,
When you do a x:forEach, the forEach action sets the current context
node to whatever the select attribute is pointing to. So, when you
point back to "$test/teamname[1]" in the x:out action, x:out can't find
that under the context that forEach is currently pointing to.
Try this instead:
<x:forEach select="$teams/doc/teamname" varStatus="status">
<%-- Same two lines as above but inside x:forEach, they return
nothing --%>
Team <c:out value="${status.count}"/>: <x:out select="." /> <br />
</x:forEach>
The only difference is that it will only give you the list once, since
it only iterates over the two teams once. Notice how I had to add a
counting mechanism as well, for which I used varStatus and the count
function.
Remember also to add <%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %> at the top of your page to
use the core library.
Hope this helps!
Chris
-----Original Message-----
From: Mark Brunkhart [mailto:[EMAIL PROTECTED]
Sent: Saturday, April 10, 2004 8:16 PM
To: [EMAIL PROTECTED]
Subject: Tomcat 5.0 - x:forEach returns incorrect result?
Hi all,
Unless we've botched our installation of Tomcat 5.0 somehow or don't
understand some nuance of JSTL 1.2 (both reasonable possibilities), I
believe we've hit a major bug with x:forEach.
Inside of a x:forEach, node-set variables defined outside the forEach
appear to change their values (see test case below). I did not see this
reported in the bug database.
Could someone test this sample on a working Tomcat 5.0 and confirm our
suspicion that this is a bug?
Thanks,
Mark
--- Test case ---
<[EMAIL PROTECTED] contentType="text/html; charset=UTF-8" session="true" %> <%@
taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<html>
<body>
<x:parse var="teams">
<doc>
<teamname>Redskins</teamname>
<teamname>Cowboys</teamname>
</doc>
</x:parse>
<x:set var="test" select="$teams/doc/*" />
Team 1: <x:out select="$test/teamname[1]" /><br />
Team 2: <x:out select="$test/teamname[2]" /><br />
<x:forEach select="$teams/doc/teamname" >
<%-- Same two lines as above but inside x:forEach, they return
nothing --%>
Team 1: <x:out select="$test/teamname[1]" /> <br />
Team 2: <x:out select="$test/teamname[2]" /> <br />
</x:forEach>
</body>
</html>
-- Test results ---
Team 1: Redskins
Team 2: Cowboys
Team 1:
Team 2:
Team 1:
Team 2:
--- Should be ---
Team 1: Redskins
Team 2: Cowboys
Team 1: Redskins
Team 2: Cowboys
Team 1: Redskins
Team 2: Cowboys
---------------------------------------------------------------------
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]