Friday, December 9, 2011

SpEL in JSF

I've been having an awful time getting SpEL to register in my JSF .xhtml pages.  I just want to do a simple

...

However, my project would give me an error saying that '(' was unexpected. This was despite the Spring Documentation saying that SpEL is the default expression language.

I made some head way when I put the following into my spring configuration xml:






This should work with JSF 2.0, but my project uses JSF 1.2 so I got a cast exception since JSF 1.2 uses the org.springframework.binding package instead.
The following should work with JSF 1.2 (I'll test this soon).




  
    
    
  
  
  

If you're using Spring Web Flow (SWF) then you'll need a different expression parser; use org.springframework.faces.webflow.FacesSpringELExpressionParser with the same constructor-args.
Note how it wraps the new SpelExpressionParser.

I've done thorough Google searches on this topic and found nothing, so as far as I can tell this is unique information!

2 comments:

  1. Hi Michael,

    its a very usefull info, thank you!

    I would like to get it work in my project(JSF 1.2 + Spring 3.0.6). Which Spring version do you use? Where did you get org.springframework.binding.expression.spel.SpringELExpressionParser ? I didn't find it in a standard Spring distribution.

    Thanks in advance!

    Alexey.

    ReplyDelete
  2. Hello Alexey,

    Thank you for the comment and the compliment!

    I was using Spring 3.0.5 and the SpringELExpressionParser is in the spring-binding module (I Google'd it and Jarvana.com told me).

    However, as it turns out in Spring 3.0.x this is NOT POSSIBLE (out of the box). It is a known defect though, see SPR-6080 for details. In short, they may put in support to use SpEL in JSFs in Spring 3.2 by giving SpEL a Unified EL interface.

    In addition, it turns out that the webflow:flow-builder-services expression-parser only affects the expression parser used in Spring.

    The good news is that if you really want to do this, and don't want to wait until Spring 3.2 you could write you own adapter for SpEL to act as a Unified EL implementation and then configure JSF to use it.

    Let me know if you need more info!

    Michael

    ReplyDelete