What are the differences between ${} and #{}?

  • #{} are for deferred expressions (they are resolved depending on the life cycle of the page) and can be used to read or write from or to a bean or to make a method call.
  • ${} are expressions for immediate resolution, as soon as they are encountered they are resolved. They are read-only.

You can read more here: http://docs.oracle.com/javaee/6/tutorial/doc/bnahr.html


A google search for "Java Server Faces dollar pound" gave the following result, from the JBoss Expression Language FAQ:

Why do some expressions start with pound and others start with dollar sign?

For the EL specification itself, there is no difference. It is up to the technology using the EL to decide what it means. For both JSP and JSF, expressions that start with a pound sign mean deferred evaluation and a dollar sign means immediate evaluation. This all has to do with when the expression will actually be evaluated during request processing. The pound sign is used in JSF components because we want the expression to be evaluated by the JSF lifecycle and not by the JSP or Facelets engine.


That's a good question! I faced it once and like you, had a lot of trouble finding the answer... until I stumbled upon this piece of documentation:

One key feature of the unified EL is its support for both immediate and deferred evaluation of expressions. Immediate evaluation means that the JSP engine evaluates the expression and returns the result immediately when the page is first rendered. Deferred evaluation means that the technology using the expression language can employ its own machinery to evaluate the expression sometime later during the page's life cycle, whenever it is appropriate to do so. Those expressions that are evaluated immediately use the ${} syntax, which was introduced with the JSP 2.0 expression language. Expressions whose evaluation is deferred use the #{} syntax, which was introduced with by JavaServer Faces technology.

Tags:

El

Jsf 2