A literal expression is evaluated to the text of the expression, which is of type String. A literal expression 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}.
By using the escape characters \$ and \# 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 6–2 shows examples of various literal expressions and their expected types and resulting values.
Table 6–2 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 to accept a deferred value expression, when referencing a value, the literal expression is evaluated at a point in the lifecycle that is determined by other factors, such as 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. For example, the commandButton tag of the guessnumber application uses a literal method expression as a logical outcome to tell the JavaServer Faces navigation system which page to display next.