javax.servlet.jsp.tagext
Interface BodyTag

All Superinterfaces:
IterationTag, JspTag, Tag
All Known Implementing Classes:
BodyTagSupport, CoreImportTag, CoreOutTag, CoreParamTag, CoreParamTag, CoreSetTag, CoreSetTag, FmtParamTag, FmtParamTag, FmtParseDateTag, FmtParseNumberTag, FormatDateTag, FormatDateTag, FormatNumberTag, FormatNumberTag, ImportTag, MessageTag, MessageTag, OutTag, ParseDateTag, ParseNumberTag, SqlParamTag, SqlParamTag, SqlQueryTag, SqlQueryTag, SqlUpdateTag, SqlUpdateTag, XmlParamTag, XmlParamTag, XmlParseTag, XmlParseTag, XmlTransformTag, XmlTransformTag

public interface BodyTag
extends IterationTag

BodyTag lets tags access the generated tag contents and it allows tag looping. For example, a SQL tag may use the enclosed SQL to update a table. A BodyTag must explicitly write the contents the enclosing stream.


 if (tag.doStartTag() == EVAL_BODY_TAG) {
   out = pageContext.pushBody();
   tag.setBodyContent(out);
   tag.doInitBody();
   do {
     ...
   } while (tag.doAfterBody() == EVAL_BODY_AGAIN);
   out = pageContent.popBody();
 }
 if (tag.doEndTag() == SKIP_PAGE)
   return;
 


Field Summary
static int EVAL_BODY_BUFFERED
          Constant returned by doStartTag to evaluate a tag body.
static int EVAL_BODY_TAG
          Deprecated.  
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Method Summary
 int doAfterBody()
          Tags call doAfterBody after processing the tag body.
 void doInitBody()
          Tags call doInitBody before processing the tag body.
 void setBodyContent(BodyContent out)
          Sets the BodyContent stream.
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
doEndTag, doStartTag, getParent, release, setPageContext, setParent
 

Field Detail

EVAL_BODY_TAG

static final int EVAL_BODY_TAG
Deprecated. 
Constant returned by doStartTag to evaluate a tag body.

See Also:
Constant Field Values

EVAL_BODY_BUFFERED

static final int EVAL_BODY_BUFFERED
Constant returned by doStartTag to evaluate a tag body.

See Also:
Constant Field Values
Method Detail

setBodyContent

void setBodyContent(BodyContent out)
Sets the BodyContent stream. A tag calls setBodyContent before calling doInitBody()

Parameters:
out - The body content for tag and its contents.

doInitBody

void doInitBody()
                throws JspException
Tags call doInitBody before processing the tag body. doInitBody is called after setBodyContent. It is called only once for each tag, even if the tag loops.

empty tags and tags returning SKIP_BODY do not call doInitBody and doAfterBody.


 if (tag.doStartTag() == EVAL_BODY_TAG) {
   out = pageContext.pushBody();
   tag.setBodyContent(out);
   tag.doInitBody();
   ...
 }
 

Throws:
JspException

doAfterBody

int doAfterBody()
                throws JspException
Tags call doAfterBody after processing the tag body. Tags writing to the output stream must write the body to the enclosing JspWriter. Tags can loop by returning EVAL_PAGE and stop by returning SKIP_PAGE.

empty tags and tags returning SKIP_BODY do not call doInitBody and doAfterBody.

Here's an example of a tag that copies its contents to the output (assuming setBodyContent sets bodyOut):


 public int doAfterBody() throws JspException
 {
   try {
     bodyOut.writeOut(bodyOut.getEnclosingWriter());
   } catch (IOException e) {
     throw JspException(String.valueOf(e));
   }
   
   return SKIP_PAGE;
 }
 

Specified by:
doAfterBody in interface IterationTag
Returns:
EVAL_PAGE to repeat the tag and SKIP_PAGE to stop.
Throws:
JspException