aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes One Tag Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "One Tag Question" Watch "One Tag Question" New topic
Author

One Tag Question

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
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


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
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.


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
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

Joined: Jul 03, 2006
Posts: 22
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


SCJP 1.4 - 95% Passed<br />SCWCD 1.4 - 89% Passed
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
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

Joined: Jul 03, 2006
Posts: 22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One Tag Question
 
Similar Threads
Doubt in doAfterBody
Regarding Classic Custom Tags
Custom Tag Qn
doAfterBody() doubt
doAfterBody()