• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

doubt in a mock exam question

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 5. Consider a JSP page that contains the following code:

10. <x uter>
11. <x:middle>
12. <x.inner></x.inner>
13. </x:middle>
14. <x uter>

Assuming the following implementation details, identify the correct statements.

1. x uter is implemented by OuterTag.java, which extends SimpleTagSupport.

2. x:middle is implemented by MiddleTag.java, which extends BodyTagSupport and has a body-content of tagdependent.

3. x:inner is implemented by InnerTag.java, which extends BodyTagSupport and has a body-content of tagdependent.

OPTIONS are:
1.OuterTag can get a reference to InnerTag by calling TagSupport.findChildrenWithClass() method.
2.MiddleTag can get a reference to OuterTag by calling TagSupport.findAncestorWithClass(this, OuterTag.class).
3.InnerTag can get a reference to OuterTag by calling TagSupport.findAncestorWithClass(this, OuterTag.class) method.
4.MiddleTag can get a reference to OuterTag by calling TagSupport.getParent() method.
5.InnerTag can get a reference to MiddleTag by calling TagSupport.getParent() method.

Answer is given 4.But I want to know why 3 is wrongsource:enthuware
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MiddleTag has a body-content of tagdependent (text) this means that the x:inner will not be invoked since it is TEXT.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please anybody tell me why option 2 is wrong .
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method findAncestorWithClass is defined in the class
SimpleTagSupport, since the inner tag has classic tag implemenation it
cannot call that method
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The method findAncestorWithClass is defined in the class
SimpleTagSupport, since the inner tag has classic tag implemenation it
cannot call that method




This method is also defined in TagSupport class.So why option 2 is wrong.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any update?
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one possibility:

For the findAncestorWithClass methods, in TagSuport the return type is Tag, while in SimpleTagSupport the return type is JspTag. Since OuterTag.class (SimpleTagSupport) is not in the inheritance hierarchy of classes that implement the Tag interface, it is not possible the Tag reference that is returned by TagSuport.findAncestorWithClass to have any association with OuterTag class (because they are not in the same inheritance hierarchy).

The Api (v2.1, p1-151) states, "A findAncestorWithClass method is available on SimpleTagSupport.This should be used,instead of
TagSupport.findAncestorWithClass(), in all cases where the desired return value may implement SimpleTag." It goes on to discuss TagAdapter usage, which is a way around the above restriction.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dee's right. A classic tag handler doesn't know anything about SimpleTags. It can only take a Tag for setParent(), and so that what it returns for getParent(), which is what's called by findAncestorWithClass(). To make it possible for a classic tag to have a SimpleTag parent, the SimpleTag gets wrapped by a TagAdapter, which does implement the Tag interface.

If getParent() returns a TagAdapter, you can then call TagAdapter's getAdaptee() method to get the SimpleTag that you really wanted.

So option 2 won't work. If you really want to use findAncestorWithClass(), you can call findAncestorWithClass(this, TagAdapter.class), followed by getAdaptee(). If you have more than one SimpleTag in the hierarchy, you'll of course need to check that the SimpleTag returned by getAdaptee() is, in fact, an instance of the SimpleTag class you're looking for.

By the way, this is way more detail than you need for the exam, but I always liked to know how things really worked.
 
I'm full of tinier men! And a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic