background image

Immediate Evaluation

<< Immediate and Deferred Evaluation Syntax | Value and Method Expressions >>
<< Immediate and Deferred Evaluation Syntax | Value and Method Expressions >>

Immediate Evaluation

tasks are performed, all done in a particular order. Therefore, it must defer evaluation of
expressions until the appropriate point in the life cycle.
Other technologies using the unified EL might have different reasons for using deferred
expressions.
Immediate Evaluation
All expressions using the ${} syntax are evaluated immediately. These expressions can only be
used within template text or as the value of a JSP tag attribute that can accept runtime
expressions.
The following example shows a tag whose value attribute references an immediate evaluation
expression that gets the total price from the session-scoped bean named cart:
<fmt:formatNumber value=
"${sessionScope.cart.total}"/>
The JSP engine evaluates the expression, ${sessionScope.cart.total}, converts it, and passes
the returned value to the tag handler.
Immediate evaluation expressions are always read-only value expressions. The expression
shown above can only get the total price from the cart bean; it cannot set the total price.
Deferred Evaluation
Deferred evaluation expressions take the form #{expr} and can be evaluated at other phases of
a page life cycle as defined by whatever technology is using the expression. In the case of
JavaServer Faces technology, its controller can evaluate the expression at different phases of the
life cycle depending on how the expression is being used in the page.
The following example shows a JavaServer Faces inputText tag, which represents a text field
component into which a user enters a value. The inputText tag's value attribute references a
deferred evaluation expression that points to the name property of the customer bean.
<h:inputText id=
"name" value="#{customer.name}" />
For an initial request of the page containing this tag, the JavaServer Faces implementation
evaluates the #{customer.name} expression during the render response phase of the life cycle.
During this phase, the expression merely accesses the value of name from the customer bean, as
is done in immediate evaluation.
For a postback, the JavaServer Faces implementation evaluates the expression at different
phases of the life cycle, during which the value is retrieved from the request, validated, and
propagated to the customer bean.
As shown in this example, deferred evaluation expressions can be value expressions that can be
used to both read and write data. They can also be method expressions. Value expressions (both
immediate and deferred) and method expressions are explained in the next section.
Unified Expression Language
Chapter 5 · JavaServer Pages Technology
149