tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rashmi Rubdi <dev_subscripti...@yahoo.com>
Subject Re: Problem when a use a x:forEach into another x:forEach
Date Sun, 28 Jan 2007 06:20:45 GMT
In both JSTL 1.1 and 1.0 specifications nothing is mentioned about nested x:forEach loops where
the inner x:forEach iterates over the parsed results of a *different* xml file.

Since this scenario is not officially mentioned anywhere, I can't really tell for sure if
the set-up you have is supposed to work or not. I didn't test it with JSTL 1.0, but since
you say it worked in JSTL 1.0 I can't see why it shouldn't work with 1.1. 

It is probably a bug in JSTL 1.1. I think this is where one could file a bug/ feature request:
http://jakarta.apache.org/taglibs/#Bugs

I also searched on ways to combine two different XML files into one with XSLT, it is possible
on the command line with a parser like Saxon, but I couldn't find ways to do it programatically
at least with XSLT 1.0 which is supported by the most recent version of Xalan which is used
by JSTL. But you can check with a XSLT mailing list if you want to take that approach. 

Another approach would be to generate a merged XML file instead of two separate XML files.

-Rashmi


----- Original Message ----
From: Sébastien Brodeur <brodseba@gmail.com>
To: Tag Libraries Users List <taglibs-user@jakarta.apache.org>
Sent: Saturday, January 27, 2007 11:06:29 PM
Subject: Re: Problem when a use a x:forEach into another x:forEach


This code work perflectly in JSTL 1.0.

On 1/27/07, Rashmi Rubdi <dev_subscriptions@yahoo.com> wrote:
>
> Sébastien,
>
> I tried your original JSP code and was able to reproduce the problem you
> indicated in your first e-mail in JSTL 1.1 and Tomcat 5.5.
>
> Then I made few changes to the JSP page as follows. I renamed some
> variables to make the code less ambiguous to read but the logic remains the
> same.
>
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"; %>
>
> <c:import var="xml_collections" url="/p/test6/collections.xml" />
> <x:parse xml="${xml_collections}" var="pCollections" scope="request"/>
>
> <c:import var="xml_books" url="/p/test6/books.xml" />
> <x:parse xml="${xml_books}" var="pBooks" scope="request"/>
>
> <x:forEach select="$pCollections/collections/collection"
> var="vCollection">
>   <x:out select="name" />
>   <x:set select="id" var="cId"/>
>
>   <ul>
>     <x:forEach select="$pBooks/books/book[collection_id=$cId]"
> var="vBook">
>       <li><x:out select="$vBook/title" /></li>
>         print test
>     </x:forEach>
>   </ul>
>
> </x:forEach>
>
>
> The code inside the inner x:forEach never executes. I think it never
> executes because the inner for loop , is not inside the context of the XML
> node in the outer for loop.
>
> If you look at the outer x:forEach loop
> the xml context node is $pCollections/collections/collection , and in the
> inner x:forEach $pBooks/books/book , does not fall under the context of the
> the external loop.
>
> If I'm not wrong, I think nesting of x:forEach works as long as the
> context of the nested x:forEach falls under that of the outer x:forEach.
>
> One solution to achieve the nested output would be to first combine the 2
> XML documents by transforming them with XSLT to create a new XML document,
> then use the new XML document to achieve the nesting. I haven't tried such a
> transformation, but I will try it in case I'm right about nesting of
> x:forEach doesn't work with unrelated contexts.
>
> Are you saying that your original code worked in JSTL1.0 and is not
> working in JSTL1.1 ? Or you tried this code for the first time in JSTL1.1and never in
> JSTL1.0?
>
> -Rashmi
>
> ----- Original Message ----
> From: Sébastien Brodeur <brodseba@gmail.com>
> To: Tag Libraries Users List <taglibs-user@jakarta.apache.org>
> Sent: Saturday, January 27, 2007 8:37:56 AM
> Subject: Re: Problem when a use a x:forEach into another x:forEach
>
>
> Hi Rashmi,
>
> Thank you for the answer.
>
> Have you been able to reproduce the error?  Is my syntax wrong (I'm not
> thrill by Node context :-) ?
>
> Even if a try to use a <c:catch> block, I got no error.  (I still have to
> look in the error log thou, first think Monday morning).
>
> 1) By using  Servlet 2.4 jar, you mean are we using a Servlet
> 2.4container?  If so, yes.
>
> 2) I already change the web.xml file to use servlet 2.4
>
> 3) I use a local version  (I made sure the .tld file are the one coming
> with
> the taglibs JSTL 1.1 package.) of the taglibs declaration.
>
> So I use:
>
> <%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
> <%@ taglib prefix="x" uri="/WEB-INF/x.tld" %>
>
> instead of:
>
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core";; %>
> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml";; %>
>
> If a try the latest, I got a error.  (Is it only namespace or some
> firewall
> may be blocking those???)
>
> Once again, thank you
>
> On 1/27/07, Rashmi Rubdi <dev_subscriptions@yahoo.com> wrote:
> >
> > Are you getting any errors in the log?
> >
> > When you upgrade from JSTL1.0 to JSTL1.1 you need to make some changes
> or
> > verify these changes:
> >
> > 1) Use Servlet 2.4 jar
> >
> > 2) Change web.xml to servlet 2.4 version:
> >
> > <web-app version="2.4"
> >          xmlns="http://java.sun.com/xml/ns/j2ee";;
> >          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";;
> >          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";;>
> >
> > 3) Change tag library declarations to:
> >
> > <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core";; %>
> > <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml";; %>
> > Similarly upgrade other JSTL namespace URIs
> >
> > -Rashmi
> >
> > ----- Original Message ----
> > From: Sébastien Brodeur <brodseba@gmail.com>
> > To: taglibs-user@jakarta.apache.org
> > Sent: Friday, January 26, 2007 2:03:02 PM
> > Subject: Problem when a use a x:forEach into another x:forEach
> >
> >
> > I'm currently migrating my application from WebSphere 5 (JSTL 1.0) to
> > WebSphere 6 (JSTL 1.1), and so far, the XML taglibs give us a lot of
> > trouble.
> >
> > For example :
> >
> >
> >
> ------------------------------------------------------------------------------------------------------
> > collections.xml
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <collections>
> >   <collection>
> >     <id>horror</id>
> >     <name>Horror novel</name>
> >   </collection>
> >   <collection>
> >     <id>scifi</id>
> >     <name>Sci-Fi novel</name>
> >   </collection>
> > </collections>
> >
> >
> >
> ------------------------------------------------------------------------------------------------------
> > books.xml
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <books>
> >   <book>
> >     <collection_id>scifi</collection_id>
> >     <title>Robots</title>
> >   </book>
> >   <book>
> >     <collection_id>scifi</collection_id>
> >     <title>The Moon is a Hashes Mistress</title>
> >   </book>
> >   <book>
> >     <collection_id>scifi</collection_id>
> >     <title>Spaceship Tropper</title>
> >   </book>
> >   <book>
> >     <collection_id>horror</collection_id>
> >     <title>This</title>
> >   </book>
> > </books>
> >
> >
> >
> ------------------------------------------------------------------------------------------------------
> > books.jsp
> >
> > <%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
> > <%@ taglib prefix="x" uri="/WEB-INF/x.tld" %>
> >
> > <c:import var="xml_collections" url="http://localhost/collections.xml";;;
> />
> > <x:parse xml="${xml_collections}" var="collections" scope="request"/>
> >
> > <c:import var="xml_books" url="http://www.localhost/books.xml";;; />
> > <x:parse xml="${xml_books}" var="books" scope="request"/>
> >
> > <x:forEach select="$collections/collections/collection"
> var="collection">
> >   <x:out select="$collection/name" />
> >   <ul>
> >     <x:forEach select="$books/books/book[collection_id=$collection/id]"
> > var="book">
> >       <li><x:out select="$book/title" /></li>
> >     </x:forEach>
> >   </ul>
> > </x:forEach>
> >
> >
> >
> ------------------------------------------------------------------------------------------------------
> > Output (WebSphere 5 using JSTL 1.0)
> >
> >   Horror novel
> >   <ul>
> >       <li>This</li>
> >   </ul>
> >
> >   Sci-Fi novel
> >   <ul>
> >       <li>Robots</li>
> >       <li>The Moon is a Hashes Mistress</li>
> >       <li>Spaceship Tropper</li>
> >   </ul>
> >
> >
> >
> ------------------------------------------------------------------------------------------------------
> >
> > Output (WebSphere 6 using JSTL 1.1)
> >
> >   Horror novel
> >   <ul>
> >   </ul>
> >   Sci-Fi novel
> >   <ul>
> >   </ul>
> >
> >
> > Any idea how to do that without changing the structure of the two XML
> > files?
> >
> > Thank!
> >
> > --
> > Sébastien Brodeur
> > brodseba@iname.com
> > Site Web : http://www.un-programmeur-php.ca/
> >
> >
> >
> >
> >
> ____________________________________________________________________________________
> > Cheap talk?
> > Check out Yahoo! Messenger's low PC-to-Phone call rates.
> > http://voice.yahoo.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> >
> >
>
>
> --
> Sébastien Brodeur
> brodseba@iname.com
> Site Web : http://www.un-programmeur-php.ca/
>
>
>
>
> ____________________________________________________________________________________
> Yahoo! Music Unlimited
> Access over 1 million songs.
> http://music.yahoo.com/unlimited
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>


-- 
Sébastien Brodeur
brodseba@iname.com
Site Web : http://www.un-programmeur-php.ca/


 
____________________________________________________________________________________
Never Miss an Email
Stay connected with Yahoo! Mail on your mobile.  Get started!
http://mobile.yahoo.com/services?promote=mail

---------------------------------------------------------------------
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