A literal expression evaluates to the text of the expression, which is of type String. It does not use the ${} or #{} delimiters.
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 for more information on this example.