background image

JavaServer Faces Applications

<< Value and Method Expressions | rvalue Expressions >>
<< Value and Method Expressions | rvalue Expressions >>

JavaServer Faces Applications

The web container evaluates a variable that appears in an expression by looking up its value
according to the behavior of PageContext.findAttribute(String), where the String
argument is the name of the variable. For example, when evaluating the expression
${customer}
, the container will look for customer in the page, request, session, and application
scopes and will return its value. If customer is not found, null is returned. A variable that
matches one of the implicit objects described in
"Implicit Objects" on page 162
will return that
implicit object instead of the variable's value.
You can alter the way variables are resolved with a custom EL resolver, which is a new feature of
the unified EL. For instance, you can provide an EL resolver that intercepts objects with the
name customer, so that ${customer} returns a value in the EL resolver instead. However, you
cannot override implicit objects in this way. See
"EL Resolvers" on page 161
for more
information on EL resolvers.
You can set the variable name, customer, when you declare the bean. See
"Creating and Using a
JavaBeans Component" on page 168
for information on how to declare a JavaBeans component
for use in your JSP pages.
To declare beans in JavaServer Faces applications, you use the managed bean facility. See
"Backing Beans" on page 309
for information on how to declare beans for use in JavaServer
Faces applications.
When referencing an enum constant with an expression, you use a String literal. For example,
consider this Enum class:
public enum Suit {hearts, spades, diamonds, clubs}
To refer to the Suit constant, Suit.hearts with an expression, you use the String literal,
"hearts". Depending on the context, the String literal is converted to the enum constant
automatically. For example, in the following expression in which mySuit is an instance of Suit,
"hearts" is first converted to a Suit.hearts before it is compared to the instance.
${mySuit ==
"hearts"}
Referring to Object Properties Using Value Expressions
To refer to properties of a bean or an Enum instance, items of a collection, or attributes of an
implicit object, you use the . or [] notation, which is similar to the notation used by
ECMAScript.
So, if you wanted to reference the name property of the customer bean, you could use either the
expression ${customer.name} or the expression ${customer["name"]}. The part inside the
square brackets is a String literal that is the name of the property to reference.
You can use double or single quotes for the String literal. You can also combine the [] and .
notations, as shown here:
Unified Expression Language
Chapter 5 · JavaServer Pages Technology
151