This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BodyTag-getPreviousOut and getPageContext().getOut()

 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a tag handler extends BodyTagSupport then inorder to get the enclosing writer we have to call getPreviousOut.But what will happen if we call getPageContext().getOut()
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getPageContext().getOut() will return you a JspWriter object which you can use to print the contents from within the tag handler method to the output stream.

getPreviousOut()is used to obtain the writer object which is wrapped in the BodyContent object. This is because BodyContent is itself a sub class of the JspWriter class.

When you return EVAL_BODY_BUFFERED in the doStartTag() in a tag imlpementing the BodyTag interface or extending the BodyTagSupport class, the BodyContent is instantiated and the current out object of the JSP is wrapped in it.

So if you want to write to the output in the doAfterBody, it wont be possible doing this:



In this case it is possible by doing:



Which return the wrapped JspWriter.

There is one more way to do the same thing as above:

BodyContent bc = getBodyContent();
JspWriter out = bc.getEnclosingWriter(); /*this too return the wrapped JspWriter*/
out.println(...);
[ July 07, 2007: Message edited by: nitin pai ]
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic