How do Custom Tags Work?
- Three features must be in place for custom tags can be used:
- Tag Library
- Collection of classes that provide the functionality of the
custom tag.
- Usually distributed in a .jar file (portability).
- Increases maintainability.
- Due to the relative simplicity, almost anyone can decipher
the code.
- Updating the code allows for one update in the central
files, not in every page that uses this code.
- New functionality can be added without changing the
already existing pages.
- Tag Handler
- "Server-side object that is created to evaluate actions
during the execution of a JSP page."
- Controls the passing of information between a JSP page and
a custom tag.
- Can be thought of as a JavaBean.
- taglib Directive
- Ties the tag library description to the JSP page.
- Sets the tag namespace prefix to be used in the JSP
page.
-
<%@ taglib
uri-"http://www.javadesktop.com/taglib/htmltool.jar"
prefix="tool"
%>
- Tag Library Descriptor
- XML document that describes a tag library as a whole
(individual tags, attributes, etc.).
- Information can be found out about a tag library without
having to instantiate objects or look at actual code.