This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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...
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.
Joined: Oct 13, 2009
Thank you both Ankit and Frits, the idea is now crystal clear.