background image

Declaring Tag Files

<< Top-Level Tag Library Descriptor Elements | PackagedTag Files >>
<< Top-Level Tag Library Descriptor Elements | PackagedTag Files >>

Declaring Tag Files

listener
Element
A tag library can specify some classes that are event listeners (see
"Handling Servlet Life-Cycle
Events" on page 103
). The listeners are listed in the TLD as listener elements, and the web
container will instantiate the listener classes and register them in a way analogous to that of
listeners defined at the WAR level. Unlike WAR-level listeners, the order in which the tag
library listeners are registered is undefined. The only subelement of the listener element is the
listener-class
element, which must contain the fully qualified name of the listener class.
Declaring Tag Files
Although not required for tag files, providing a TLD allows you to share the tag across more
than one tag library and lets you import the tag library using a URI instead of the tagdir
attribute.
tag-file
TLD Element
A tag file is declared in the TLD using a tag-file element. Its subelements are listed in
Table 8­8
.
TABLE 8­8
tag-file
Subelements
Element
Description
description
(optional) A description of the tag.
display-name
(optional) Name intended to be displayed by tools.
icon
(optional) Icon that can be used by tools.
name
The unique tag name.
path
Where to find the tag file implementing this tag, relative to the root of the web application
or the root of the JAR file for a tag library packaged in a JAR. This must begin with
/WEB-INF/tags/
if the tag file resides in the WAR, or /META-INF/tags/ if the tag file
resides in a JAR.
example
(optional) Informal description of an example use of the tag.
tag-extension
(optional) Extensions that provide extra information about the tag for tools.
Unpackaged Tag Files
Tag files placed in a subdirectory of /WEB-INF/tags/ do not require a TLD file and don't have to
be packaged. Thus, to create reusable JSP code, you simply create a new tag file and place the
code inside it.
Tag Library Descriptors
Chapter 8 · Custom Tags in JSP Pages
249