background image

Declaring Tag Handlers

<< PackagedTag Files | Declaring Tag Attributes for Tag Handlers >>
<< PackagedTag Files | Declaring Tag Attributes for Tag Handlers >>

Declaring Tag Handlers

Tag files bundled in a JAR require a tag library descriptor. Tag files that appear in a JAR but are
not defined in a TLD are ignored by the web container.
When used in a JAR file, the path subelement of the tag-file element specifies the full path of
the tag file from the root of the JAR. Therefore, it must always begin with /META-INF/tags/.
Tag files can also be compiled into Java classes and bundled as a tag library. This is useful when
you wish to distribute a binary version of the tag library without the original source. If you
choose this form of packaging, you must use a tool that produces portable JSP code that uses
only standard APIs.
Declaring Tag Handlers
When tags are implemented with tag handlers written in Java, each tag in the library must be
declared in the TLD with a tag element. The tag element contains the tag name, the class of its
tag handler, information on the tag's attributes, and information on the variables created by the
tag (see
"Tags That Define Variables" on page 232
).
Each attribute declaration contains an indication of whether the attribute is required, whether
its value can be determined by request-time expressions, the type of the attribute, and whether
the attribute is a fragment. Variable information can be given directly in the TLD or through a
tag extra info class.
Table 8­9
lists the subelements of the tag element.
TABLE 8­9
tag
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.
tag-class
The fully qualified name of the tag handler class.
tei-class
(optional) Subclass of javax.servlet.jsp.tagext.TagExtraInfo. See
"Declaring
Tag Variables for Tag Handlers" on page 254
.
body-content
The body content type. See
"body-content Element" on page 252
.
variable
(optional) Declares an EL variable exposed by the tag to the calling page. See
"Declaring Tag Variables for Tag Handlers" on page 254
.
attribute
Declares an attribute of the custom tag. See
"Declaring Tag Attributes for Tag
Handlers" on page 252
.
Tag Library Descriptors
Chapter 8 · Custom Tags in JSP Pages
251