The Java EE 5 Tutorial

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).

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.

body-content

The body content type. See body-content Element.

variable

(optional) Declares an EL variable exposed by the tag to the calling page. See Declaring Tag Variables for Tag Handlers.

attribute

Declares an attribute of the custom tag. See Declaring Tag Attributes for Tag Handlers.

dynamic-attributes

Whether the tag supports additional attributes with dynamic names. Defaults to false. If true, the tag handler class must implement the javax.servlet.jsp.tagext.DynamicAttributes interface.

example

(optional) Informal description of an example use of the tag. 

tag-extension

(optional) Extensions that provide extra information about the tag for tools. 

body-content Element

You specify the type of body that is valid for a tag by using the body-content element. This element is used by the web container to validate that a tag invocation has the correct body syntax and is used by page-composition tools to assist the page author in providing a valid tag body. There are three possible values: