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
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.
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.