Immediate and Deferred Evaluation Syntax in java

Chapter 7 - Building JSP Pages Using the Expression Language (EL)

    Immediate and Deferred Evaluation Syntax in java

  • Immediate and Deferred Evaluation Syntax

    The EL supports both immediate and deferred evaluation of expressions. Immediate evaluation is evaulted the epression and the result returned soon as the page is first rendered.

    Deferred evaluation is the technology using the expression language can use its own machinery to evaluate the expression sometime later during the page lifecycle.

    Immediate Evaluation

    All expressions using the ${} syntax are evaluated immediately. These expressions can be used only within template text or as the value of a 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 JavaServer Faces implementation 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.

    Deferred Evaluation

    Deferred evaluation expressions take the form #{expr} and can be evaluated at other form of a page lifecycle.

    In JavaServer Faces technology, its controller can evaluate the expression at different phases of the lifecycle, depending on how the expression is being used in the page.

    The following example shows a JavaServer Faces h:inputText tag, which represents a text field component into which a user enters a value.

    The h: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}" / >

    In JavaServer Faces implementation evaluates the #{customer.name} expression during the render-response phase of the lifecycle.

    It accesses the value of name from the customer bean, as is done in immediate evaluation.

    In JavaServer Faces implementation evaluates the expression at different phases of the lifecycle, during which the value is retrieved from the request, validated, and propagated to the customer bean.

    Deferred evaluation expressions can be:

    • Value expressions that can be used to both read and write data

    • Method expressions

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy