In JSF, What is the difference between the expressions ${} and #{}?
Answered
In JSF, What is the difference between the expressions ${} and #{}?
Best answer
- The expression ${} represents immediate evaluation which means that the expression is evaluated and the result returned as soon as the page is first rendered. Immediate evaluation expressions are always read-only value expressions.
For example, ${student.name} uses immediate evaluation syntax where the expression accesses the name property of Student, gets its value, adds the value to the response, and gets rendered on the page.
- The expression #{} represents deferred evaluation which means that the technology using the expression language can use its own machinery to evaluate the expression sometime later during the page’s lifecycle. Deferred evaluation expressions can be ‘Value expressions’ that can be used to both read and write data and ‘Method expressions’.
For example, #{student.name} uses deferred value syntax where the expression accesses the name property of Student, gets its value and optionally can modify the value, adds the value to the response and gets rendered on the page. Here, the evaluation of the expression is deferred.