background image

rvalue Expressions

<< JavaServer Faces Applications | Where Value Expressions Can Be Used >>
<< JavaServer Faces Applications | Where Value Expressions Can Be Used >>

rvalue Expressions

${customer.address[
"street"]}
Properties of an enum can also be referenced in this way. However, as with JavaBeans
component properties, the Enum class's properties must follow JavaBeans component
conventions. This means that a property must at least have an accessor method called
get<Property>
(where <Property> is the name of the property) so that an expression can
reference it.
For example, say you have an Enum class that encapsulates the names of the planets of our
galaxy and includes a method to get the mass of a planet. You can use the following expression
to reference the method getMass of the Planet Enum class:
${myPlanet.mass}
If you are accessing an item in an array or list, you must use either a literal value that can be
coerced to int or the [] notation with an int and without quotes. The following examples could
all resolve to the same item in a list or array, assuming that socks can be coerced to int:
${customer.orders[1]}
${customer.orders.socks}
In contrast, an item in a Map can be accessed using a string literal key; no coercion is required:
${customer.orders[
"socks"]}
An rvalue expression also refers directly to values that are not objects, such as the result of
arithmetic operations and literal values, as shown by these examples:
${
"literal"}
${customer.age + 20}
${true}
${57}
The unified expression language defines the following literals:
Boolean: true and false
Integer: as in Java
Floating point: as in Java
String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as
\\
Null: null
You can also write expressions that perform operations on an enum constant. For example,
consider the following Enum class:
public enum Suit {club, diamond, heart, spade }
Unified Expression Language
The Java EE 5 Tutorial · September 2007
152