It's not a secret anymore!
The moose likes JSP and the fly likes Don't understand nesting issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Don Watch "Don New topic

Don't understand nesting issues

John Summers
Ranch Hand

Joined: Oct 06, 2003
Posts: 125
Hi all.
I'm trying to write my own tags and having a few problems. They are kind of similar to the struts logic:iterate tag. The outer one extends javax.servlet.jsp.tagext.IterationTag. The will be used like this:
<john uter id="currentBook" collection="books" type="org.john.Book" >
<john:inner value='<%= currentBean.getBookTitle() %>' />
</john uter>
Within the code for the john uter tag it gets the collection 'books' out of the request scope (other stuff has put it there). Now, as it iterates it stores each Book from the collection in PageContext.setAttribute.
However, this does not work. It appears that the inner tag cannot identify this reference 'currentBean' and thus does not compile properly at request time. However THIS works:
<john uter id="currentBook" collection="books" type="org.john.Book" >
<%= currentBean.getBookTitle() %>
</john uter>
Can someone explain the issue here? Why does a nested tag not have access to attributes set by outer tags?
[ January 02, 2004: Message edited by: John Summers ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

John, if you click the 'disable smilies' checkbox on your posts, the colons in your tags won't get converted.
Secondly, I'm not completely sure that I understand your issue. You say that the inner tag does not 'see' currentBean, but you don't describe how this is being set or retrieved.
An inner tag will have access to the page context, so attributes set by the outer tag will be available to an inner tag if set in the start method of the outer tag.

[Asking smart questions] [About Bear] [Books by Bear]
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
My guess would be that the problem is with exppressions in attributes, not especially with your iner tag. Try modifying your second example to say:

My guess is that won't work either.
Have you declared your new tag as accepting "rtexpr" in your tld file ?

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
John Summers
Ranch Hand

Joined: Oct 06, 2003
Posts: 125
Finally after countless hours I have found the problem. I had not defined a
<tei-class> in the .tld file and implemented a TagExtraInfo subclass to make the scripting variables available.
Well, I am just starting...
It just never occured to me I would even have to do such a thing. I just assumed the container made the scripting variables of parent tags available to child ones...
thanks for your help anyhows.
I agree. Here's the link:
subject: Don't understand nesting issues
jQuery in Action, 3rd edition