background image

Defining aTag AttributeType

<< Method Expressions | Deactivating Expression Evaluation >>
<< Method Expressions | Deactivating Expression Evaluation >>

Defining aTag AttributeType

Method expressions can be used only in tag attributes and only in the following ways:
With a single expression construct, where bean refers to a JavaBeans component and method
refers to a method of the JavaBeans component:
<some:tag value=
"#{bean.method}"/>
The expression is evaluated to a method expression, which is passed to the tag handler. The
method represented by the method expression can then be invoked later.
With text only:
<some:tag value=
"sometext"/>
Method expressions support literals primarily to support action attributes in JavaServer
Faces technology. When the method referenced by this method expression is invoked, it
returns the String literal, which is then coerced to the expected return type, as defined in
the tag's TLD.
Defining a Tag Attribute Type
As explained in the previous section, all kinds of expressions can be used in tag attributes.
Which kind of expression and how that expression is evaluated (whether immediately or
deferred) is determined by the type attribute of the tag's definition in the TLD (see
"Tag Library
Descriptors" on page 247
) file that defines the tag.
If you plan to create custom tags (see
Chapter 8, "Custom Tags in JSP Pages"
), you need to
specify for each tag in the TLD what kind of expression it accepts.
Table 5­2
shows the three
different kinds of tag attributes that accept EL expressions, and gives examples of expressions
they accept and the type definitions of the attributes that must be added to the TLD. You cannot
use #{} syntax for a dynamic attribute, meaning an attribute that accepts
dynamically-calculated values at runtime. Section 2.3.2 of the JavaServer Pages 2.1 specification
refers to these attributes. Neither can you use the ${} syntax for a deferred attribute.
TABLE 5­2
Definitions of Tag Attributes That Accept EL Expressions
Attribute Type
Example Expression
Type Attribute Definition
dynamic
"literal"
<rtexprvalue>true</rtexprvalue>
${literal}
<rtexprvalue>true</rtexprvalue>
Unified Expression Language
The Java EE 5 Tutorial · September 2007
156