background image

Using the Unified EL

<< Configuring a Bean | The Life Cycle of a JavaServer Faces Page >>
<< Configuring a Bean | The Life Cycle of a JavaServer Faces Page >>

Using the Unified EL

Notice that the application configuration resource file does not configure the userNumber
property. Any property that does not have a corresponding managed-property element will be
initialized to whatever the constructor of the bean class has the instance variable set to. The next
section explains more about using the unified EL to reference backing beans.
For more information on configuring beans using the managed bean creation Facility, see
"Configuring Beans" on page 439
.
Using the Unified EL to Reference Backing Beans
To bind UI component values and objects to backing bean properties or to reference backing
bean methods from UI component tags, page authors use the unified expression language (EL)
syntax defined by JSP 2.1. As explained in
"Unified Expression Language" on page 146
, some of
the features this language offers are:
Deferred evaluation of expressions
The ability to use a value expression to both read and write data
Method expressions
These features are all especially important for supporting the sophisticated UI component
model offered by JavaServer Faces technology.
Deferred evaluation of expressions is important because the JavaServer Faces life cycle is split
into separate phases so that component event handling, data conversion and validation, and
data propagation to external objects are all performed in an orderly fashion. The
implementation must be able to delay the evaluation of expressions until the proper phase of
the life cycle has been reached. Therefore, its tag attributes always use deferred evaluation
syntax, which is distinguished by the #{} delimiters.
"The Life Cycle of a JavaServer Faces Page"
on page 313
describes the life cycle in detail.
In order to store data in external objects, almost all JavaServer Faces tag attributes use lvalue
value expressions, which are expressions that allow both getting and setting data on external
objects.
Finally, some component tag attributes accept method expressions that reference methods that
handle component events, or validate or convert component data.
To illustrate a JavaServer Faces tag using the unified EL, let's suppose that the userNo tag of the
guessNumber
application referenced a method rather than using LongRangeValidator to
perform the validation of user input :
<h:inputText id=
"userNo"
value=
"#{UserNumberBean.userNumber}"
validator=
"#{UserNumberBean.validate}" />
This tag binds the userNo component's value to the UserNumberBean.userNumber backing bean
property using an lvalue expression. It uses a method expression to refer to the
Backing Beans
The Java EE 5 Tutorial · September 2007
312