File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes classic tag inside a simple tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "classic tag inside a simple tag" Watch "classic tag inside a simple tag" New topic
Author

classic tag inside a simple tag

Indunil Dasanayaka
Greenhorn

Joined: Dec 12, 2005
Posts: 11
<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?


Shit Happens...
Indunil Dasanayaka
Greenhorn

Joined: Dec 12, 2005
Posts: 11
seems as if no one there to help me
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836

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.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Indunil Dasanayaka
Greenhorn

Joined: Dec 12, 2005
Posts: 11
Thanks Charly
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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 ]

Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classic tag inside a simple tag