• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method findAncestorWithClass ??

 
Ritu varada
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was a question posed in j2eecertificate.com
Consider the following JSP code. How can the child tag table get a reference to the tag handler of the parent tag body? [Check all correct answers]

1. getHandler() method from the TagSupport class.
2. findAncestorWithClass() static method in the TagSupport class.
3. getParent() from the Tag interface.
4. getChild() from the Tag interface.
5. getBodyContent() from the BodyTagSupport class.

I did not realise that findAncestorWithClass() was a static method because in the Head First book, I remember it being called as
findAncestorWithClass(this,WayOuterTag.class).

I thought that static methods don't have access to 'this'. Hopefully, its not a java beginner question. Pardon me if it is. That would only mean I don't know my Java, which is not a happy thought. Appreciate somebody's input.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ritu ,
The TagSupport.findAncestorWithClass is a static method and i belive in H&F its not written. May be you want to see the specs or can see the docs for method signatures .

when you handler will extends the TagSupport you can give a call to this function to get the parent tag.

Hope that helps.

Sawan
 
Ritu varada
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sawan, Thanks for your reply. I did check the specs and it gave it as a static method. My doubt has more to do with the way the method was invocated in the Head First book.
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ritu varada:
Hopefully, its not a java beginner question.

Sorry to dash your hopes ;-) but if you extend TagSupport, then you can call static methods without naming the class.



--Dale--
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic