javax.servlet.jsp.tagext

Interface Tag

Known Subinterfaces:
BodyTag
Known Implementing Classes:
BodyTagSupport, TagSupport

public interface Tag

The Tag interface defines the basic protocol between a Tag handler and JSP page implementation class. It defines the life cycle and the methods to be invoked at start and end tag.

There are several methods that get invoked to set the state of a Tag handler. The Tag handler is required to keep this state so the page compiler can choose not to reinvoke some of the state setting.

The page compiler guarantees that setPageContext and setParent will all be invoked on the Tag handler, in that order, before doStartTag() or doEndTag() are invoked on it. The page compiler also guarantees that release will be invoked on the Tag handler before the end of the page.

Here is a typical invocation sequence:

 
 
 ATag t = new ATag();

 -- need to set required information 
 t.setPageContext(...);
 t.setParent(...);
 t.setAttribute1(value1);
 t.setAttribute2(value2);

 -- all ready to go
 t.doStartTag();
 t.doEndTag();
 
 ... other tags and template text

 -- say one attribute is changed, but parent and pageContext have not changed
 t.setAttribute2(value3);
 t.doStartTag()
 t.doEndTag()

 ... other tags and template text

 -- assume that this new action happens to use the same attribute values
 -- it is legal to reuse the same handler instance,  with no changes...
 t.doStartTag();
 t.doEndTag();

 -- OK, all done
 t.release()
 
 

The Tag interface also includes methods to set a parent chain, which is used to find enclosing tag handlers.

Field Summary

static int
EVAL_BODY_INCLUDE
Evaluate body into existing out stream.
static int
EVAL_PAGE
Continue evaluating the page.
static int
SKIP_BODY
Skip body evaluation.
static int
SKIP_PAGE
Skip the rest of the page.

Method Summary

int
doEndTag()
Process the end tag.
int
doStartTag()
Process the start tag for this instance.
Tag
getParent()
void
release()
Called on a Tag handler to release state.
void
setPageContext(PageContext pc)
Set the current page context.
void
setParent(Tag t)
Set the current nesting Tag of this Tag.

Field Details

EVAL_BODY_INCLUDE

public static final int EVAL_BODY_INCLUDE
Evaluate body into existing out stream. Valid return value for doStartTag. This is an illegal return value for doStartTag when the class implements BodyTag, since BodyTag implies the creation of a new BodyContent.

Field Value:
1


EVAL_PAGE

public static final int EVAL_PAGE
Continue evaluating the page. Valid return value for doEndTag().

Field Value:
6


SKIP_BODY

public static final int SKIP_BODY
Skip body evaluation. Valid return value for doStartTag and doAfterBody.

Field Value:
0


SKIP_PAGE

public static final int SKIP_PAGE
Skip the rest of the page. Valid return value for doEndTag.

Field Value:
5

Method Details

doEndTag

public int doEndTag()
            throws JspException
Process the end tag. This method will be called on all Tag objects.


doStartTag

public int doStartTag()
            throws JspException
Process the start tag for this instance.

See Also:
BodyTag


getParent

public Tag getParent()

Returns:
the current parent


release

public void release()
Called on a Tag handler to release state. The page compiler guarantees this method will be called on all tag handlers, but there may be multiple invocations on doStartTag and doEndTag in between.


setPageContext

public void setPageContext(PageContext pc)
Set the current page context. Called by the page implementation prior to doStartTag().

This value is *not* reset by doEndTag() and must be explicitly reset by a page implementation


setParent

public void setParent(Tag t)
Set the current nesting Tag of this Tag. Called by the page implementation prior to doStartTag().

This value is *not* reset by doEndTag() and must be explicitly reset by a page implementation. Code can assume that setPageContext has been called with the proper values before this point.


Copyright © 1999-2000 The Apache Software Foundation. All Rights Reserved.