• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SimpleTagSupport.findAncestorWithClass(...)

 
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Could someone please help me undertand what this method does.

This is what the API docs say, but I cannot make head or tail of it (slow-brain-monday perhaps)


--------------------------------------------------------------------------------
findAncestorWithClass
public static final JspTag findAncestorWithClass(JspTag from, java.lang.Class<?> klass)
Find the instance of a given class type that is closest to a given instance. This method uses the getParent method from the Tag and/or SimpleTag interfaces. This method is used for coordination among cooperating tags.
For every instance of TagAdapter encountered while traversing the ancestors, the tag handler returned by TagAdapter.getAdaptee() - instead of the TagAdpater itself - is compared to klass. If the tag handler matches, it - and not its TagAdapter - is returned.

The current version of the specification only provides one formal way of indicating the observable type of a tag handler: its tag handler implementation class, described in the tag-class subelement of the tag element. This is extended in an informal manner by allowing the tag library author to indicate in the description subelement an observable type. The type should be a subtype of the tag handler implementation class or void. This addititional constraint can be exploited by a specialized container that knows about that specific tag library, as in the case of the JSP standard tag library.

When a tag library author provides information on the observable type of a tag handler, client programmatic code should adhere to that constraint. Specifically, the Class passed to findAncestorWithClass should be a subtype of the observable type.


Parameters:
from - The instance from where to start looking.
klass - The subclass of JspTag or interface to be matched
Returns:
the nearest ancestor that implements the interface or is an instance of the class specified
--------------------------------------------------------------------------------

 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nidhi,

Have a look at my notes chapter 9.7

Regards,
Frits
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Frits,

I did look through your notes. Kudos on creating them - they are pretty thorough & extensive.

However, related to my question, I could just find this info (quoting from your notes):

SimpleTagSupport has a method:

· static JspTag findAncestorWithClass(JspTag from, Class aClass)

which resembles:

· static Tag findAncestorWithClass(Tag from, Class aClass)

from the TagSupport class

The SimpleTagSupport method however will look for simple classes: if a TagAdapter is found on
the way it will compare the class against the Adaptee of the TagAdapter(getAdaptee())



I may be missing something here, but trying to figure this out:

--> Does ancestor in findAncestorWithClass(...) refer to ancestor in class hierarchy? as in super type, or super's super & so on? [This is all the more confusing because the Parent in getParent(...) refers to the nesting tag, not the parent as in class hierarchy.]

-->What is the role of the second argument, class?

-->When would you ever use this method?



 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Does ancestor in findAncestorWithClass(...) refer to ancestor in class hierarchy?


This is used when you are nesting tags, You are looking for a tag handler-class in one of the surrounding tags.

What is the role of the second argument, class?


A tag handler of one of the surrounding tags is of a certain class, you can look for a particulair one

When would you ever use this method?


When you are nesting tags like:


Regards,
Frits
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic