This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 10 Q#9

 
tehika danait
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tehika it would be better if you post the question here. Not everyone has the book at hand all the time...
 
tehika danait
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 2275
80
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both Ankit and Frits, the idea is now crystal clear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic