This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I did a search on EVAL_BODY_BUFFERED and didn't find a good answer as to what this actually does. Taking the word Buffered, I would assume that it would hold what was in the body into a "Buffer" and not release it until the buffer was filled, or was told to flush. But how does that relate to a Body of a tag? In the API it shows this. But it hasn't clicked in my brain.
If EVAL_BODY_BUFFERED is returned, then a BodyContent object will be created (by code generated by the JSP compiler) to capture the body evaluation. The code generated by the JSP compiler obtains the BodyContent object by calling the pushBody method of the current pageContext, which additionally has the effect of saving the previous out value. The page compiler returns this object by calling the popBody method of the PageContext class; the call also restores the value of out.
I was waiting for someone who has better knowledge to take a bite....but anyways... When this is returned, I am assuming that a BufferedOutput object is created and placed on the pageContext. For the output generated from evaluation of the rest of the Body is first added to this BufferedOutput (which is differect from the implicit out object). Thus you are NOT continously writing to the out obj, but you write to it (from this BufferedOutput obj) after the complete evaluation of the Body. Makes sense.....anyother thoughts please ? regds. - satya
IF you would follow these steps the whole thing will become clear.Here is how it goes about. 1.in the doStartTag the the implicit out object of pageContext is used for writing the response to client.obtained by using pageContext.getOut() 2. Now if the doStartTag method returns EVAL_BODY_BUFFERED then a new bufferedobject is created by filling that object with the contents of the body in between the tags.As you must me aware of a stack(LIFO STRUCTURE) this buffered object is stored in the stack when the pageContext.pushBody() is executed(all this stuff is done all by itself internally so don't worry about it) now if try to acess the out object using pageContext.getOut() what we get is the BodyContent object and not the one to write to the client. Now when we enter the doEndTag() the pageContext.popBody() is executed removing the bodyContent objectt.In this we now have our implicit out object again for writing back to the client.Simple as this