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 HFJS errata in the errata file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFJS errata in the errata file?" Watch "HFJS errata in the errata file?" New topic
Author

HFJS errata in the errata file?

Jose Esteban
Ranch Hand

Joined: Nov 28, 2004
Posts: 102
Page 550 of HFJS:

Q3. Given a JSP page:
11. <my:tag1>
12. <my:tag2>
13. <my:tag3 />
14. </my:tag2>
15. </my:tag1>

The tag handler for my:tag1 is Tag1Handler and extends TagSupport.
The tag handler for my:tag2 is Tag2Handler and extends SimpleTagSupport.
The tag handler for my:tag3 is Tag3Handler and extends TagSupport.

The errata file says that:

"[550] question 3;
Option C is invalid.
Unfortunately, that leaves us with a mock question that doesn't not have a valid answer."

I agree that option C is invalid but, what about option B:

B. Only classic tags are considered in composing the parent/child tag hierarchy; therefore, Tag3Handler may use the getParent method only once to gain access to the instance of Tag1Handler.

According to the JSP 2.0 spec:
Page 304 (2-54): "The JSP page implementation object invokes setPageContext and setParent, in that order, before invoking doStartTag() or doEndTag()."

So setParent is the method that sets the parent of the tag.

Page 308 (2-58): "public void setParent(Tag t)
Set the parent (closest enclosing tag handler) of this tag handler."

So the setParent(Tag t) method sets the parent to the CLOSEST TAG HANDLER (and NOT TO THE CLOSEST SIMPLE TAG HANDLER).

According to this, I think option B should be marked as TRUE.

What do you think?
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
So the setParent(Tag t) method sets the parent to the CLOSEST TAG HANDLER (and NOT TO THE CLOSEST SIMPLE TAG HANDLER).

According to this, I think option B should be marked as TRUE.

What do you think?


I thinkg that 'TAG HANDLER' here is used in a more general way, just to identify a Tag handler, would this belong to the simple or classic model. B cannot be right because the immediate ancestor of tag 3 is 2 and not 1. In order to get to 1, my tag 3 should invoke getParent twice. Don't forget that polymorphism is possible amongst simple and classic tags. That means that thanks to the JspTag interface it's possible for a simple tag handler to get a reference to a tag written following the classic approach.


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Jose Esteban
Ranch Hand

Joined: Nov 28, 2004
Posts: 102
Originally posted by Marco Tedone:


I thinkg that 'TAG HANDLER' here is used in a more general way, just to identify a Tag handler, would this belong to the simple or classic model.


I don't know. JSP specs usually are very precise using the terminology. And the term "Simple tag handler" appears 67 times in the specs. I'll have to try.

Originally posted by Marco Tedone:

In order to get to 1, my tag 3 should invoke getParent twice.


You're wrong. As you say, a Simple tag can have a Classic Tag parent, since Simple tag's getParent() method returns a JspTag. But a Classic Tag CANNOT have a Simple tag parent, since Classic tag's getParent() method returns a Tag.

my:tag3 is a Classic tag and my:tag2 is a Simple tag, so invoking getParent() in Tag3Handler won't get my:tag2. That's for sure.

What I wonder is if you get my:tag1 invoking getParent() in Tag3Handler. I need to try.
Jose Esteban
Ranch Hand

Joined: Nov 28, 2004
Posts: 102
Originally posted by Marco Tedone:


I thinkg that 'TAG HANDLER' here is used in a more general way, just to identify a Tag handler, would this belong to the simple or classic model.


You were right on this. JSP specs aren't as precise as I thought. I've tried an example and it doesn't work as I thought. To get my:tag1 from my:tag3 you cannot use getParent(). You can get it using findAncestorWithClass().

So answer B in the question is false.
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
Originally posted by Jose Esteban:


You're wrong. As you say, a Simple tag can have a Classic Tag parent, since Simple tag's getParent() method returns a JspTag. But a Classic Tag CANNOT have a Simple tag parent, since Classic tag's getParent() method returns a Tag.



According to HFJSP (540), it is also possible the other way round, only using a TagAdapter class.

For reference, you can visit the following link
Jose Esteban
Ranch Hand

Joined: Nov 28, 2004
Posts: 102
Originally posted by Marco Tedone:


In order to get to 1, my tag 3 should invoke getParent twice.


I said that you were wrong on this.

Besides, from the link you gave us:
"a classic tag handler (one that implements Tag) cannot have a SimpleTag as its parent."

What is true is that:
"A classic Tag Handler can call getAdaptee() to retrieve the encapsulated SimpleTag instance."

But that's a different thing.

Anyway, I think that both of us have clear the concepts about this matter.
 
 
subject: HFJS errata in the errata file?
 
Similar Threads
check this head forst question
HF chap.10 : don't understand answer for Q3
Doubt on Tag Handlers
SimpleTags + ClassicTags + getParent()
Another Simple Tag & Classic Tag handler mock exam question - what's YOUR answer?