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

SimpleTags + ClassicTags + getParent()

 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have a question regarding "getParent()" method from SimpleTag and Tag interfaces.

(HFJ&S page 550, question 3 - option C).

"Tag3Handler MAY use the getParent method twice to gain access to the instance of Tag1Handler" wish is a ClassTag as well. (book says : FALSE - errata)


My questiob is:

According to my tests, we could even get access to "<my:tag2>" wich is a SimpleTag using "getParent()".

In fact, what we COULDN`T do is to get access to "its methods" (ClassCastException).

The point is.."classic tags (inner - <my:tag3> can access simpletags(outer - <my:tag2> ..and therefore to get access to the classictag (outer - <my:tag1> .


was i clear?
Does it make sense??


Tks in advance.

Tks.
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone please?
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The point is.."classic tags (inner - <my:tag3> can access simpletags(outer - <my:tag2> ..and therefore to get access to the classictag (outer - <my:tag1> .




<tag1 .. > -- Classic tag
<tag2 .. > -- Simple tag
<tag3 ..> -- classic tag
</tag3>
</tag2>
</tag1>
/QUOTE]

This is valid. You can nest simple and custom tags. Here the tag3 use the TagAgaptor to wrap the tag2 tag. TagAdaptor class wrap the SimpleTag and expose it as a Tag interface. The TagAdaptor take SimpleTag as argument to constructor and give all methods as the Tag interface. Only the getParent and the getAdoptee methods are implemented all the other Tag methods return UnSupportedException.

Hope this help

Thanks
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right Narendra,

But when "tag3" tries to get access to the "tag2�s methods", it returns "ClassCastException", ins�t it?

And another thing...so it��s **CORRECT** to say that ClassicTags "can" also get access to SimpleTags "DIRECTLY"?

or is it **WRONG**? BECAUSE it needs to utilize a TagAdpter "INDIRECTLY" for this?


Please folks, help us. It�s important for the exam.

Tks a lot.

cya.
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic