The Java EE 5 Tutorial

Declaring Tag Attributes in Tag Files

To declare the attributes of a custom tag defined in a tag file, you use the attribute directive. A TLD has an analogous attribute element (see Declaring Tag Attributes for Tag Handlers). Table 8–3 lists the attribute directive attributes.

Table 8–3 attribute Directive Attributes

Attribute 

Description 

description

(optional) Description of the attribute. Defaults to no description. 

name

The unique name of the attribute being declared. A translation error results if more than one attribute directive appears in the same translation unit with the same name.

A translation error results if the value of a name attribute of an attribute directive is equal to the value of the dynamic-attributes attribute of a tag directive or the value of a name-given attribute of a variable directive.

required

(optional) Whether this attribute is required (true) or optional (false). Defaults to false.

rtexprvalue

(optional) Whether the attribute’s value can be dynamically calculated at runtime by an expression. Defaults to true. When this element is set to true and the attribute definition also includes either a deferred-value or deferred-method element then the attribute accepts both dynamic and deferred expressions.

type

(optional) The runtime type of the attribute’s value. Defaults to java.lang.String.

deferredValue

(optional) Indicates whether the attribute accepts deferred value expressions. Only one of deferredValue or deferredMethod can be true. If deferredValueType is specified, the default for deferredValue is true. Causes a translation error if specified in a tag file with a JSP version less than 2.1.

deferredValueType

(optional) The type resulting from the evaluation of the attribute’s value expression. The default is java.lang.String if no type is specified. If both deferredValueType and deferredValue are specified, deferredValue must be true. If deferredValue is true, the default of deferredValueType is java.lang.Object. Causes a translation error specified in a tag file with a JSP version less than 2.1.

deferredMethod

(optional) Indicates whether the tag attribute accepts deferred method expressions. If deferredMethod and deferredMethodSignature are specified then deferredMethod must be true. The default of deferredMethod is true if deferredMethodSignature is specified, otherwise the default of deferredMethod is false. The presence of a deferred-method element in an attribute definition precludes the inclusion of a deferred-value element. Causes a translation error if specified in a tag file with a JSP version less than 2.1.

deferredMethodSignature

(optional) The signature of the method to be invoked by the expression defined by the accompanying deferredMethod attribute. If deferredMethod is true and this attribute is not specified, the method signature defaults to void methodName(). Causes a translation error if specified in a tag file with a JSP version less than 2.1.

fragment

(optional) Whether this attribute is a fragment to be evaluated by the tag handler (true) or a normal attribute to be evaluated by the container before being passed to the tag handler.

If this attribute is true:

You do not specify the rtexprvalue attribute. The container fixes the rtexprvalue attribute at true.

You do not specify the type attribute. The container fixes the type attribute at javax.servlet.jsp.tagext.JspFragment.

Defaults to false.