background image

Composite Expressions

<< Literal Expressions | Resolving Expressions >>
<< Literal Expressions | Resolving Expressions >>

Composite Expressions

If you have a literal expression that includes the reserved ${} or #{} syntax, you need to escape
these characters as follows.
By creating a composite expression as shown here:
${
'${'}exprA}
#{
'#{'}exprB}
The resulting values would then be the strings ${exprA} and #{exprB}.
The escape characters \$ and \# can be used to escape what would otherwise be treated as an
eval-expression:
\${exprA}
\#{exprB}
The resulting values would again be the strings ${exprA} and #{exprB}.
When a literal expression is evaluated, it can be converted to another type.
Table 5­3
shows
examples of various literal expressions and their expected types and resulting values.
TABLE 5­3
Literal Expressions
Expression
Expected Type
Result
Hi
String
Hi
true
Boolean
Boolean.TRUE
42
int
42
Literal expressions can be evaluated immediately or deferred and can be either value or method
expressions. At what point a literal expression is evaluated depends on where it is being used. If
the tag attribute that uses the literal expression is defined as accepting a deferred value
expression, then the literal expression references a value and is evaluated at a point in the life
cycle that is determined by where the expression is being used and to what it is referring.
In the case of a method expression, the method that is referenced is invoked and returns the
specified String literal. The commandButton tag of the Guess Number application uses a literal
method expression as a logical outcome to tell the JavaServer Faces navigation system which
page to display next. See
"Navigation Model" on page 307
for more information on this example.
Unified Expression Language
Chapter 5 · JavaServer Pages Technology
159