tags:

views:

189

answers:

2

I can use objects from my Java Beans within .jsp files by using the Expression Language (EL). Therefore I can get my value by typing ${foo.bar}. But I can also use #{foo.bar}.

Can anybody explain the difference or provide a link with meaningful information?

+2  A: 

#{foo.bar} syntax is from the JSF expression language. Some bright spark thought it would be a good idea to use a different syntax to JSP EL (i.e. ${foo.bar}). I think some JSP containers are tolerant of this cockup, and let you use either one.

skaffman
So I could use ${...} anytime I want and #{...} only in case of using JSF which means that #{...} has the same functionality... That really must have been a bright spark :DThanks ;)
Marcus
JSF was a ghastly mess from day one, and they've been trying to paper over the cracks ever since.
skaffman
Ok... but why is it a mess? I'm new to it, therefore I haven't much experience with it ;)
Marcus
+6  A: 

This is covered in the JSP 2.1 spec.

In J2EE/JEE, #{expr} is used for deferred evaluation and ${expr} for immediate evaluation. Deferred expressions (#{expr}) expressions can only be used with tag attributes that accept them. This is a J2EE convention, but other domains could impose their own meaning (e.g. if you wanted to use EL in your own templates).

McDowell
Aha, interesting, I wasn't aware of that. +1
skaffman