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

HF chap.10 : don't understand answer for Q3

 
Pierre Schuffenecker
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an issue regarding to the answer for the mock exam question 3 of the chapter 10 (custom tags) from the HF servlets and JSP book.

I have:

with
Tag1Handler extends TagSupport for tag1 (a Classic tag)
Tag2Handler extends SimpleTagSupport for tag2 (a Simple tag)
Tag3Handler extends TagSupport for tag3 (a Classic tag)

It is said that Tag3Handler must use getParent() twice to access the Tag1Handler instance.

But, on page 540, I can read:
"Using getParent() method, a Classic tag can access Classic tag parents, and a Simple tag can access either a Classic or Simple parents".

By runnig getParent() the first time, Tag3Handler will access the Tag2Handler instance, which is an instance of a Simple tag!
So... how can I run getParent() a second time on that result, if a Classic tag cannot access a Simple Tag parent?
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You had a slip in your reasoning but you are right (it is the Classic tag handler Tag3Handler which cannot access the Simple tag tag2).

The answer should not be marked as correct in the book (there's no correct answer in this question).
 
siva raju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pierre,

The answer in the book is correct. The reason goes thus,

If the parent of a classic tag is a simple tag, the container encapsulates the simple tag in a TagAdapter object and returns it from the getParent() method of Tag3Handler.
The TagAdapter implements the Tag interface, so you can again call getParent() on it again to get the Tag1Handler.
If you need access to the simple tag object, you can call TagAdapter.getAdaptee(). In fact,
TagAdapter.getParent() == TagAdapter.getAdaptee().getParent()
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you can't get the "Simple parent" without using a TagAdapter so, in my opinion, the answer to the question shouldn't be marked as true.
 
siva raju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose,

I see what you are getting at. But see the exact wordings of the answer,

"Tag3Handler may use the getParent method twice to gain access to the instance of Tag1Handler"

which is quite true. The answer does not suggest that we gain access to the instance to Tag2Handler.
 
Pierre Schuffenecker
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose, Siva,

you pointed the problem.
The answer:
"Tag3Handler may use the getParent method twice to gain access to the instance of Tag1Handler"
is true, but only if the TagAdapter is used.
Without that, it is wrong.

I think that the HF team must clarify that.

regards
Pierre
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic