jueves, 2 de diciembre de 2010

Escaping Spring EL

Months without blogging and finally today I've found a reason to write something! It's the first time Spring has failed me big time!!! And doing a trivial task to boot!!!

Let's recapitulate, I'm trying to inyect a simple String property in a bean. The value I have to inyect is: #{fwk:path('/')}. Simple, huh? Well, not so much it seems.

Can you spot the problem right there? I'll help you a little. Spring 3.0 includes an expression language. Fine...if it weren't for the fact that it uses #{} as the expression delimiter. Of course, that can cause a lot of trouble because:
  • It seems Spring lacks the ability to turn off the EL if you're not using it
  • It seems Spring lacks the ability to configure the pattern
  • It seems Spring lacks the ability to escape single quotes inside the expression
  • The documentation isn't stellar this time
In the end I was able to solve the problem. I'm showing you how, just inject this (it took me several approaches to find it so it's a little useful snippet I guess):

#{ '#{' }fwk:path('/')}

Great, isn't it? Elegant, clear, concise...wow! Now...c'mon!!! Am I missing something here?? Either I've lost my mojo (just this time) or SpringSource has some room for improvement! Please, prove me wrong.