File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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?
thanks!
john
[ January 02, 2004: Message edited by: John Summers ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Frank Carver
Sheriff

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 frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
John Summers
Ranch Hand

Joined: Oct 06, 2003
Posts: 125
Ah!!
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.
john
 
wood burning stoves
 
subject: Don't understand nesting issues
 
Similar Threads
what struts tld syntax is for HTML OPTION ?
html:select html:options error, no getter. please help
bodycontent - JSP or tagdependent?
BeanUtils.populate error
Coding tag handlers or tag files together