Interface Tag

  • All Known Subinterfaces:
    BodyTag
    All 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 Detail

      • SKIP_BODY

        static final int SKIP_BODY
        Skip body evaluation. Valid return value for doStartTag and doAfterBody.
        See Also:
        Constant Field Values
      • EVAL_BODY_INCLUDE

        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.
        See Also:
        Constant Field Values
      • SKIP_PAGE

        static final int SKIP_PAGE
        Skip the rest of the page. Valid return value for doEndTag.
        See Also:
        Constant Field Values
      • EVAL_PAGE

        static final int EVAL_PAGE
        Continue evaluating the page. Valid return value for doEndTag().
        See Also:
        Constant Field Values
    • Method Detail

      • setPageContext

        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

        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.

      • getParent

        Tag getParent()
        Returns:
        the current parent
      • doEndTag

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

        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.