It is the responsibility of the tag handler to manipulate the body content.  For example the tag 
handler may take the body content, convert it into a 
String
 using the 
bodyContent.getString
 method and then use it.  Or the tag handler may take the body 
content and write it out into its enclosing JspWriter using the 
bodyContent.writeOut
method.
A tag handler that implements 
BodyTag
 is treated as one that implements 
Tag
, except that 
the 
doStartTag
 method can either return SKIP_BODY or EVAL_BODY_TAG, not 
EVAL_BODY_INCLUDE.  If EVAL_BODY_TAG is returned, then a BodyContent object 
will be created to capture the body evaluation. This object is obtained by calling the  
pushBody
 method of the current 
pageContext
, which additionally has the effect of 
saving the previous 
out
 value.  The object is returned through a call to the 
popBody
method of the 
PageContext
 class; the call also restores the value of 
out
.
Properties
There is only one additional property: 
bodyContent
setBodyContent(BodyContent)
Set the 
bodyContent
 property. It will be invoked at most once per action 
invocation. It will be invoked before 
doInitBody
 and it will not be invoked if 
there is no body evaluation.
When 
setBodyContent
 is invoked, the value of the implicit object out has 
already been changed in the 
pageContext
 object.  The body passed will have 
not data on it.
Methods
There are two action methods:
doInitBody()
Invoked before the 
first
 time the body is to be evaluated. Not invoked in empty tags or 
in tags returning SKIP_BODY in 
doStartTag()
.
Depending on TagExtraInfo values, the JSP container will resynchronize some variable 
values after the 
doInitBody
 invocation.
This method may throw a JspException.
doAfterBody()
Invoked after 
every
 body evaluation. Not invoked in empty tags or in tags returning 
SKIP_BODY in 
doStartTag.
  If 
doAfterBody
 returns EVAL_BODY_TAG, a 
new evaluation of the body will happen (followed by another invocation of 
Chapter 5
Tag Extensions
104




JSP Web Hosting JavaServer Pages Specifications JSP Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.