background image

Variable Directive Attributes

<< Directive Attributes | Variable Synchronization Behavior >>
<< Directive Attributes | Variable Synchronization Behavior >>

Variable Directive Attributes

To declare an EL variable exposed by a tag file, you use the variable directive. A TLD has an
analogous variable element (see
"Declaring Tag Variables for Tag Handlers" on page 254
).
Table 8­4
lists the variable directive attributes.
TABLE 8­4
variable
Directive Attributes
Attribute
Description
description
(optional) An optional description of this variable. Defaults to no description.
name-given |
name-from-attribute
Defines an EL variable to be used in the page invoking this tag. Either name-given
or name-from-attribute must be specified. If name-given is specified, the value is
the name of the variable. If name-from-attribute is specified, the value is the
name of an attribute whose (translation-time) value at the start of the tag
invocation will give the name of the variable.
Translation errors arise in the following circumstances:
1. Specifying neither name-given nor name-from-attribute or both.
2. If two variable directives have the same name-given.
3. If the value of a name-given attribute of a variable directive is equal to the
value of a name attribute of an attribute directive or the value of a
dynamic-attributes
attribute of a tag directive.
alias
Defines a variable, local to the tag file, to hold the value of the EL variable. The
container will synchronize this value with the variable whose name is given in
name-from-attribute
.
Required when name-from-attribute is specified. A translation error results if
used without name-from-attribute.
A translation error results if the value of alias is the same as the value of a name
attribute of an attribute directive or the name-given attribute of a variable
directive.
variable-class
(optional) The name of the class of the variable. The default is java.lang.String.
declare
(optional) Whether or not the variable is declared. True is the default.
scope
(optional) The scope of the variable. Can be either AT_BEGIN, AT_END, or NESTED.
Defaults to NESTED.
Variable Synchronization
The web container handles the synchronization of variables between a tag file and a calling
page.
Table 8­5
summarizes when and how each object is synchronized according to the
object's scope.
Encapsulating Reusable Content Using Tag Files
Chapter 8 · Custom Tags in JSP Pages
239