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

Question on BodyContent.

 
Gaurav Sahni
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy CattlePeople!!!

The BodyContent class contains methods that you use to write it's contents to the output.

Q1. As per the convention, the writer should be obtained using the tag handler's getPreviousOut()method. Why is this so ? The BodyTagSupport already has the access to the pageContext object which can be used to obtain the out writer. Can't we write the contents of body using this writer ?

Q2. Is the method getPreviousOut() equivalent to calling getBodyContent().getEnclosingWriter()?

Thanx in advance.
Gaurav.
 
Guido Schoepp
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q2. Is the method getPreviousOut() equivalent to calling getBodyContent().getEnclosingWriter()?


This is exactly what's the reference implementation does:


Q1. As per the convention, the writer should be obtained using the tag handler's getPreviousOut()method. Why is this so ? The BodyTagSupport already has the access to the pageContext object which can be used to obtain the out writer. Can't we write the contents of body using this writer?


I assume this is because a tag implementation could return another JspWriter (e.g. for processing nested tags), which is not identical to the JspWriter object of the pageContext variable.

Guido
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic