wood burning stoves 2.0*
The moose likes JSP and the fly likes Parent for Classic and simple tags in JSP HFSJ doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Parent for Classic and simple tags in JSP HFSJ doubt" Watch "Parent for Classic and simple tags in JSP HFSJ doubt" New topic
Author

Parent for Classic and simple tags in JSP HFSJ doubt

Swapnil Dharane
Ranch Hand

Joined: Apr 22, 2012
Posts: 49

Hi all,

There are two types of Custom tags that can be used in JSP 2.0 environment,Classic and Simple. A simple tag can be nested in a classic as well as a simple tag i.e,A simple tag can have Classic as well as Simple Parent. But a Classic tag mostly has a classic tag as a parent.

The reason I came to know is as follows:
getParent() method, in case of Classic tag returns Tag type of object Which is difficult to cast into SimpleTag.Why so?

Again, We can cast from Tag to the tag handler class in case of classic tag which should not happen since Classic tag Handler is a subclass of tagSupport which implements Tag.(SuperClass to Subclass cast)
Same is the case for SimpleTag only SimpleTagSupport and JspTag replace Tag and TagSupport (superclass to subclass cast)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

SimpleTag.getParent() returns JspTag, Tag.getParent() returns Tag. Now Tag and SimpleTag both extends JspTag, so from SimpleTag.getParent() both objects implementing Tag and SimpleTag can be returned. However, SimpleTag is not compatible with Tag. That means that Tag.getParent() cannot return a SimpleTag. Casting won't help you out because that will usually fail with a ClassCastException. The solution that is provided is to use TagAdapter.

When a (classic) Tag is placed inside a SimpleTag, then the Tag returned by Tag.getParent() will be a TagAdapter. You can check for that, and then cast to it and retrieve the SimpleTag from it:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Swapnil Dharane
Ranch Hand

Joined: Apr 22, 2012
Posts: 49

Got it
Thanks Rob :D
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

You're welcome :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parent for Classic and simple tags in JSP HFSJ doubt