• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

One Tag Question

 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which of the following cases will the method doAfterBody() of a tag handler be invoked?

a This method will always be called when the body of the tag is not empty.

b This method will be called only when the body of the tag IS empty.

c This method will be called only when doStartTag() returns Tag.EVAL_BODY_INCLUDE or BodyTag.EVAL_BODY_BUFFERED.
It'll also be called when doAfterBody() (ie. the same method) returns IterationTag.EVAL_BODY_AGAIN.

d This method will be called only when doEndTag() returns Tag.EVAL_BODY_INCLUDE or BodyTag.EVAL_BODY_BUFFERED.
doEndTag() is called at the end of the tag processing. It can only return SKIP_PAGE or EVAL_PAGE.

e This method will be called if doAfterBody() returns IterationTag.EVAL_BODY_AGAIN.

I think the correct answer should be C. Can anyone please confirm.

Thanks
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that C is correct; E is also correct, but is a subset of the answer to C... If it's only choose 1 option, then C is the most general; if it's choose 2 then C and E.

The method isn't always invoked, clearly A is wrong. B is incorrect - what's the point of invoking a body when there isn't one? Hence doAfterBody() won't be invoked either. D is wrong - these are illegal return constants for doEndTag(), which incidentally is invoked after the final execution of doAfterBody() anyway, thus making this scenario nonsensical.
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for confirming Charles. BTW only one answer was required to be chosen and hence i chose C.

Thanks Again.
 
Yi Yuan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't agree with you and I think the correct answer is E.
To c : This method will be called "only" when doStartTag() returns Tag.EVAL_BODY_INCLUDE or BodyTag.EVAL_BODY_BUFFERED.
The keyword "only" make it wrong.

Originally posted by Sandeep Chhabra:
In which of the following cases will the method doAfterBody() of a tag handler be invoked?

a This method will always be called when the body of the tag is not empty.

b This method will be called only when the body of the tag IS empty.

c This method will be called only when doStartTag() returns Tag.EVAL_BODY_INCLUDE or BodyTag.EVAL_BODY_BUFFERED.
It'll also be called when doAfterBody() (ie. the same method) returns IterationTag.EVAL_BODY_AGAIN.

d This method will be called only when doEndTag() returns Tag.EVAL_BODY_INCLUDE or BodyTag.EVAL_BODY_BUFFERED.
doEndTag() is called at the end of the tag processing. It can only return SKIP_PAGE or EVAL_PAGE.

e This method will be called if doAfterBody() returns IterationTag.EVAL_BODY_AGAIN.

I think the correct answer should be C. Can anyone please confirm.

Thanks
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This method will be called "only" when doStartTag() returns Tag.EVAL_BODY_INCLUDE or BodyTag.EVAL_BODY_BUFFERED.
The keyword "only" make it wrong.
I don't think so: the only valid return values for doStartTag() are SKIP_BODY, EVAL_BODY_INCLUDE and EVAL_BODY_BUFFERED.

If SKIP_BODY is returned, execution always jumps straight to doEndTag().

If EVAL_BODY_INCLUDE is returned, the body is evaluated before execution reaches doAfterBody().

If EVAL_BODY_BUFFERED is returned, some buffer methods are invoked, the body is evaluated, then execution reaches doAfterBody().

So we conclude that only a return value of EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED will cause doAfterBody() to be invoked. Do you still disagree? If so, for what reason?
 
Yi Yuan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the method doAfterBody() returns EVAL_BODY_AGAIN, the method doAfterBody() of a tag handler will also be invoked.

So we cannot say that "only" when doStartTag() returns Tag.EVAL_BODY_INCLUDE or BodyTag.EVAL_BODY_BUFFERED will the method doAfterBody() be invoked.

I am Chinese and my English is not very good. I don't know whether I have express myself clearly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic