background image

Declaring Tag Variables for Tag Handlers

<< attribute Subelements | Defines an EL Variable >>
<< attribute Subelements | Defines an EL Variable >>

Declaring Tag Variables for Tag Handlers

</attribute>
...
</tag>
Declaring Tag Variables for Tag Handlers
The example described in
"Tags That Define Variables" on page 232
defines an EL variable
departmentName
:
<tlt:iterator var=
"departmentName" type="java.lang.String"
group=
"${myorg.departmentNames}">
<tr>
<td><a href=
"list.jsp?deptName=${departmentName}">
${departmentName}</a></td>
</tr>
</tlt:iterator>
When the JSP page containing this tag is translated, the web container generates code to
synchronize the variable with the object referenced by the variable. To generate the code, the
web container requires certain information about the variable:
Variable name
Variable class
Whether the variable refers to a new or an existing object
The availability of the variable
There are two ways to provide this information: by specifying the variable TLD subelement or
by defining a tag extra info class and including the tei-class element in the TLD (see
"TagExtraInfo Class" on page 262
). Using the variable element is simpler but less dynamic.
With the variable element, the only aspect of the variable that you can specify at runtime is its
name (with the name-from-attribute element). If you provide this information in a tag extra
info class, you can also specify the type of the variable at runtime.
Table 8­11
lists the subelements of the variable element.
TABLE 8­11
variable
Subelements
Element
Description
description
(optional) A description of the variable.
Tag Library Descriptors
The Java EE 5 Tutorial · September 2007
254