Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Don't understand nesting issues

 
John Summers
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
John Summers
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic