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.
posted 10 years ago
Thank you both Ankit and Frits, the idea is now crystal clear.
SCJP 6(90%), SCWCD 5(92%)
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop