Tag interface:
The interface of a classic tag handler that does not want to manipulate its body. The Tag interface defines the basic protocol between a Tag handler and JSP page implementation class.
Properties:
The Tag interface specifies the setter and getter methods for the core pageContext and parent properties.
Methods:
There are two main actions: doStartTag and doEndTag. Once all appropriate properties have been initialized, the doStartTag and doEndTag methods can be invoked on the tag handler. Between these invocations, the tag handler is assumed to hold a state that must be preserved. After the doEndTag invocation, the tag handler is available for further invocations (and it is expected to have retained its properties).
Empty and Non-Empty Action:
If the TagLibraryDescriptor file indicates that the action must always have an empty action, by an entry of “empty”, then the doStartTag() method must return SKIP_BODY.
Otherwise, the doStartTag() method may return SKIP_BODY or EVAL_BODY_INCLUDE.
If SKIP_BODY is returned the body, if present, is not evaluated.
If EVAL_BODY_INCLUDE is returned, the body is evaluated and “passed through” to the current out.
Life Cycle:
1.The tags may have the default values, so the default values are readed and after that setPageContext(), setParent() and the setters of all the attributes are invoked.
2. After the initialization of all the properties doStartTag() method is envoked. It may return SKIP_BODY or EVAL_BODY_INCLUDE.
3. doEndTag() is called if and only if the tag ends normally without raising an exception.
4. Some setters may be called again before tag handler is reused.
Example : setParent() is called if it is reused within the same page but at different level, setPageContext() is called if its used in another page and attribute setters are called if the values differs.
5.Once all invocations on the tag handler are completed, the release() method is invoked on it. Once a release method is invoked all properties, including parent and pageContext, are assumed to have been reset to an unspecified value. The page compiler guarantees that release() will be invoked on the Tag handler before the handler is released to the GC.
Next article : Life Cycle of JSP “BodyTag” interface.
Leave a Reply