1 / 8

Creating JSP Custom Tag Libraries

Creating JSP Custom Tag Libraries. Celsina Bignoli bignolic@smccd.net. Custom Tag Libraries using Java. tag extension mechanism set of classes and interfaces to develop custom actions in JSP tag handler class that implements the behavior of a custom action

Download Presentation

Creating JSP Custom Tag Libraries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CreatingJSP Custom TagLibraries Celsina Bignoli bignolic@smccd.net

  2. Custom Tag Libraries using Java • tag extension mechanism set of classes and interfaces to develop custom actions in JSP • tag handler class that implements the behavior of a custom action • simple tag handler simplified mechanism for developing custom actions based on a single interface (SimpleTag), introduced in JSP2.0 • does not allow scripting as part of the action body

  3. Tag Library Components • tag handler class that implements the behavior of a custom action • Tag Library Descriptor(TLD)file XML file that maps action names to their tag handler class and describes all attributes supported by each custom action

  4. Tag Handler Class • It is essentially a Bean • Implements SimpleTag interface • Most commonly by extending the SimpleTagSupport class • Methods • setJspContext(JspContext) • doTag() • setter methods for each attributes of the custom action • setJspBody(JspFragment)

  5. Method Calls <prefix:actionName attr1=“value1” attr2=“value2” > body </prefix:actionName> setAttr1(“value1”) setAttr1(“value1”) doTag()

  6. Tag Handler Lifecycle • A new tag handler instance is created each time by the container by calling the provided zero-args constructor. • simple tag handlers are never cached and reused by the JSP container. • The setJspContext() and setParent() methods are called by the container. The setParent() method is only called if the element is nested within another tag invocation. • The setters for each attribute defined for this tag are called by the container. • If a body exists, the setJspBody() method is called by the container to set the body of this tag, as a JspFragment. If the action element is empty in the page, this method is not called at all. • The doTag() method is called by the container. • All tag logic, iteration, body evaluations, etc. occur in this method.

  7. JSP Fragment • the JSP container converts the body of a custom action into an object of type javax.servlet.jsp.tagext.JspFragment • this fragment is associated with the JspContext of the page where it is defined • The container calls the method invoke() on the JspFragment causing all dynamic elements in the fragment to be executed • their output is combined with static template code if any to form an evaluation result

  8. Exceptions • catch exceptions and deal with them or rethrow them as JspException or JspTagException • public JspTagException() • public JspTagException(String message) • public JspTagException(String message, Throwable rootCause) • public JspTagException(Throwable rootCause) • can be caught and handled in a JSP page using JSTL <c:catch> action.

More Related