Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getAncesterWithClass exists or not

 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This is a question from Enthuware:
Consider two cooperating tags orchestra:band and orchestra:instrument, which are used as follows:

<orchestra:band>
<orchestra:instrument name="trumpet" />
<orchestra:instrument name="violin" />
</orchestra:band>

Given that band is implemented by BandTag and instrument is implemented by InstrumentTag, both of which extend BodyTagSupport.

The band tag needs to get the "names" (the value of the name attribute of instrument tags) of all the instruments that it contains. Which of the following approaches will you use?


Options:
Please select two options:

a) In doStartTag method of BandTag, call super.getChildren() to get an array of Tags. Iterate through the Tags, and call getName() after casting each element to InstrumentTag.

b) In doStartTag method of BandTag, call pageContext.getChildren() to get an array of Tags. Iterate through the Tags, and call getName() after casting each element to InstrumentTag.

c) Define a method addName() in BandTag. In the doStartTag() of InstrumentTag, get a reference to BandTag through super.getAncesterWithClass() and call the addName() method.

d) Define a method addName() in BandTag. In the doStartTag() of InstrumentTag, get a reference to BandTag through pageContext.getAncesterWithClass() and call the addName() method.

e) Define a method addName() in BandTag. In the doStartTag() of InstrumentTag, get a reference to BandTag through super.getParent(), and call the addName() method.

Which options you think are correct..

I think option E is correct and all other options seem to be wrong.

Thanks & Regards,
Sudhakar Karnati
 
Rodrigo Vieira
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe C is correct as well, because when you call super you are referecing BodyTagSupport thats implements the method getAncesterWithClass() but i am not 100% sure.
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option E must be the correct option.
maybe C is correct as well, because when you call super you are referecing BodyTagSupport thats implements the method getAncesterWithClass() but i am not 100% sure.

From my knowledge There is no method "getAncesterWithClass" in BodyTagSupport or its superclass TagSupport. Infact the correct method is findAncestorWithClass.
Correct me if I am wrong.
 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my knowledge There is no method "getAncesterWithClass" in BodyTagSupport or its superclass TagSupport. Infact the correct method is findAncestorWithClass.


Even i am thinking the same.

But the answers are C & E.

No explanation given for the option C.


Thanks & Regards,
Sudhakar Karnati
[ July 31, 2008: Message edited by: sudhakar karnati ]
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No explanation given for the option C


It means that might be by mistake option C is given has correct answer.
So have believe on yourself,I checked the API,method does not exist at at all.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the API,method does not exist at at all.
The findAncestorWithClass method exists on SimpleTagSupport, so perhaps that's where the confusion with the question author lies. This question is also misleading in the way it uses () for methods, since calling addName() won't help either - you'd need to call addName(this) I expect.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and they only even hint at casting in option (a) - of course you'd also need to cast the Tag (or JspTag for a SimpleTag) returned from the getParent or findAncestorWithClass methods to BandTag before invoking addName(this), or you'll get a compilation error. I assume this was implicit in what was written for the options.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic