Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

immediate vs deferred evaluation for reading bean properties

I am still unclear about the use of JSF immediate evaluation vs deferred evaluation, mainly because the online examples almost never seem to use the former method.

I have seen a fair amount of JSF Examples, including those contained in http://docs.oracle.com/javaee/6/tutorial/doc/, and I am a bit puzzled by the fact that I almost only ever see examples with #{} instead of ${}, even when all we're doing is reading a bean property.

From my understanding of these two uses, ${} can only be used to read bean properties, not to write. I have yet to find a clear explanation of the exact difference of immediate vs deferred evaluation in respect to the JSF life cycle and what difference that would make for reading bean properties.

If everyone always uses the #{} for reading bean properties, when would you recommend the use of ${}?

So, in summary:

  • Why does everyone seem to prefer #{} over ${} when reading bean properties?
  • When would you recommend using ${} instead of #{}?
  • Can you give me an example of where using ${} would have a different result from using #{} (and can you explain why the result is different)?
like image 420
Student Avatar asked Mar 20 '13 14:03

Student


People also ask

What is deferred evaluation?

A formal measurement of student learning that may include, but is not. limited to, an examination, a test, an assignment or a project. Exceptional. circumstances. Serious illness, personal or family tragedy, religious observance, legal.

What is immediate evaluation?

Immediate evaluation means that the expression is evaluated and the result returned as soon as the page is first rendered.

Which are the evaluation types of UEL?

Immediate and Deferred Evaluation Syntax. The unified EL supports both immediate and deferred evaluation of expressions.


1 Answers

In Facelets, the ${} is treated as #{}, so there's technically no difference and it's always deferred.

In JSP 2.0 and older, the ${} won't autocreate the managed bean when it's not in scope yet. You can thus only use it if you can guarantee that #{} on the very same managed bean is been used somewhere before in the component tree and also take view build time vs view render time lifecycle into account. In all JSP versions, the ${} can't set submitted values of JSF input components in model. All in all, mixing them is potentially confusing to starters and in long term even also to yourself and therefore not recommended.

See also:

  • Difference between JSP EL, JSF EL and Unified EL
like image 136
BalusC Avatar answered Sep 28 '22 03:09

BalusC