aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Chapter 10 Q#9 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Chapter 10 Q#9" Watch "Chapter 10 Q#9" New topic
Author

Chapter 10 Q#9

tehika danait
Ranch Hand

Joined: Oct 13, 2009
Posts: 52
Hi Ranchers
to me the correct answer for Q9 of chapter 10 is C
if I am mistaken and B is correct answer what is the reason?
thanks in advance


SCJP 6(90%), SCWCD 5(92%)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

tehika it would be better if you post the question here. Not everyone has the book at hand all the time...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
tehika danait
Ranch Hand

Joined: Oct 13, 2009
Posts: 52
The Question say:
Given:

Assume that the tag has been properly configured to allow body content.
which, if inserted at line 03, would cause the JSP code
<mytags:mytag>BodyContent</mytags:mytag>

to output BodyContent?
A. return SKIP_BODY;
B. return EVAL_BODY_INCLUDE
C. return EVAL_BODY_BUFFERED
D. return BODY_CONTENT
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

If your doStartTag method returns EVAL_BODY_BUFFERED, then the body content is not written to the client, instead an instance of BodyContent is created and setBodyContent method of your tag class is called. Its then the responsibility of your doEndTag method to actually write the contents of the BodyContent object to the client...
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1660
    
  25

Hi Tehika,

Apart from the doEndTag() method you can also write the body to page in the doAfterBody() method.

Look at the following drawing:

If you return EVAL_BODY_INCLUDE you will come directly to the Body Evaluation where the body is "evaluated" which means in this case it is directly output to the page, but if you return EVAL_BODY_BUFFERED the BodyContent object is created and the doInitBody() is called. (like Ankit was saying)
This is the place where you can still do things before the body is "evaluated". You can't output the body yet to the page as it is only available after the "body evaluation" which means in this case that the buffer of the BodyContent is filled with the body. After this you can ouput the body in either the doAfterBody() or the doEndTag() method.

Watch out for trick questions: if you don't override the doStartTag() method in a class that extends the BodyTagSupport class the default implementation is that it will return EVAL_BODY_BUFFERED from the doStartTag() method! Hench the default implementation return types are made bold in this picture.

I hope this helps.

Regards,
Frits
tehika danait
Ranch Hand

Joined: Oct 13, 2009
Posts: 52
Thank you both Ankit and Frits, the idea is now crystal clear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chapter 10 Q#9