Search code examples
jspeldeferredevaluation

Is there a difference between immediate (${}) and deferred (#{}) evaluation in JSP?


In the Java Unified Expression Language there are two base types of EL syntax:

${expression for immediate evaluation}
#{expression for deferred evaluation}

I understand the difference between these two in JaveServer Faces: JSF has a sense of a varying life cycle, and immediate expressions are always evaluated at page render while deferred expressions could be evaluated at page render, at postback, or both.

However, the difference is not clear to me for JavaServer Pages. JSP, from what I can tell, does not have the sense of life cycles that JSF has. In fact, I was somewhat surprised to learn that the deferred syntax was even legal in JSP. However, I now know that it is, because a backwards-compatibility <jsp-config> setting is available in the deployment descriptor to disable the detection of deferred syntax for pre-JUEL JSPs that use that syntax for some other purpose:

<deferred-syntax-allowed-as-literal>

So, the question is, what's the difference? Deferred syntax obviously can't mean exactly the same thing in JSP that it means in JSF, but I can't find any documentation anywhere that describes how to use deferred syntax for JSP.

Are they simply synonymous in JSP?


Solution

  • I found this from other forums, I hope it helps.

    Check out the preface section of the JSP2.1 specification. Deferred expressions only really apply to custom tags where you have specified that the attribute is deferred. For the most part, I don't bother with them.

    Basically If you use #{deferredSyntax} in template text, it triggers a translation error (they don't make sense outside of a tag attribute)

    If you use #{deferredSyntax} in a tag attribute, it depends upon the tld declaration for what version of JSP that taglib supports. - JSP version supported < 2.1 == treat as literal - JSP version supported >= 2.1 : treat as deferred attribute - as long as it is marked as such.

    You can set the page attribute:

    <%@page deferredSyntaxAllowedAsLiteral="true"%>