Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classic tag inside a simple tag

 
Indunil Dasanayaka
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<testcl:classicTag1>
<testsim:simpleTag1>
<testcl:classicTag2/>
</testsim:simpleTag1>
</testc1:classicTag1>

since getParent()method in classic tag returns a Tag reference and simple tags are not implemented Tag interface is it possible to access classicTag1 from the classicTag2 using getparent()method?

anybody home to help me?
 
Indunil Dasanayaka
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems as if no one there to help me
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

since getParent()method in classic tag returns a Tag reference and simple tags are not implemented Tag interface is it possible to access classicTag1 from the classicTag2 using getparent()method?

anybody home to help me?[/QB]


Yes,

When the Tag.getParent() method encounters a SimpleTag, it wraps it into a TagAdapter instance (TagAdapter extends Tag but throws UnsupportedOperationException for all method implementations except getParent() and getAdaptee()).

This means that when navigating through the hierarchy of nested tags using Tag.getParent(), you need to check if the instance returned is actually a TagAdapter, which always encloses a SimpleTag. If so, use the TagAdapter.getAdaptee() method to extract the original SimpleTag.

This is also the reason why the SimpleTagSupport.findAncestorWithClass() method is preferred over the TagSupport.findAncestorWithClass(), because the SimpleTagSupport method automatically unwraps any TagAdapters, exposing the result simply as a JspTag (as with all Tags SimpleTags).

You may also want to check the J2EE API for TagAdapter:

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/TagAdapter.html


Hope that clears it up!

Charles.
 
Indunil Dasanayaka
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Charly
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We know with the use getParent() method SimpleTags can access SimpleTag as
well as ClassicTag parents whereas Classic tags can access ONLY
ClassicTag parents.

Here is an example to access SimpleTag parent with ClassicTag child.

Jsp Page code



Menu Tag Handler



MenuItem Tag Handler



Output


[ December 22, 2005: Message edited by: Vishnu Prakash ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic