Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parent for Classic and simple tags in JSP HFSJ doubt

 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it
Thanks Rob :D
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic