background image

Value and Method Expressions

<< Immediate Evaluation | JavaServer Faces Applications >>
<< Immediate Evaluation | JavaServer Faces Applications >>

Value and Method Expressions

Value and Method Expressions
The unified EL defines two kinds of expressions: value expressions and method expressions.
Value expressions can either yield a value or set a value. Method expressions reference methods
that can be invoked and can return a value.
Value Expressions
Value expressions can be further categorized into rvalue and lvalue expressions. Rvalue
expressions are those that can read data, but cannot write it. Lvalue expressions can both read
and write data.
All expressions that are evaluated immediately use the ${} delimiters and are always rvalue
expressions. Expressions whose evaluation can be deferred use the #{} delimiters and can act as
both rvalue and lvalue expressions. Consider these two value expressions:
<taglib:tag value=
"${customer.name}" />
<taglib:tag value=
"#{customer.name}" />
The former uses immediate evaluation syntax, whereas the latter uses deferred evaluation
syntax. The first expression accesses the name property, gets its value, and the value is added to
the response and rendered on the page. The same thing can happen with the second expression.
However, the tag handler can defer the evaluation of this expression to a later time in the page
life cycle, if the technology using this tag allows it.
In the case of JavaServer Faces technology, the latter tag's expression is evaluated immediately
during an initial request for the page. In this case, this expression acts as an rvalue expression.
During a postback, this expression can be used to set the value of the name property with user
input. In this situation, the expression acts as an lvalue expression.
Referencing Objects Using Value Expressions
Both rvalue and lvalue expressions can refer to the following objects and their properties or
attributes:
JavaBeans components
Collections
Java SE enumerated types
Implicit objects
See
"Implicit Objects" on page 162
for more detail on the implicit objects available with JSP
technology.
To refer to these objects, you write an expression using a variable name with which you created
the object. The following expression references a JavaBeans component called customer.
${customer}
Unified Expression Language
The Java EE 5 Tutorial · September 2007
150