javax.servlet.jsp.tagext
Interface BodyTag
- All Superinterfaces:
- Tag
- All Known Implementing Classes:
- BodyTagSupport
- public interface BodyTag
- extends Tag
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_PAGE);
out = pageContent.popBody();
}
if (tag.doEndTag() == SKIP_PAGE)
return;
Field Summary |
static int |
EVAL_BODY_TAG
Constant returned by doStartTag to evaluate a tag body. |
EVAL_BODY_TAG
public static final int EVAL_BODY_TAG
- Constant returned by doStartTag to evaluate a tag body.
setBodyContent
public 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
public 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();
...
}
doAfterBody
public 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;
}
- Returns:
- EVAL_PAGE to repeat the tag and SKIP_PAGE to stop.