Showing posts with label JSTL. Show all posts
Showing posts with label JSTL. Show all posts

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!

Monday, October 24, 2011

Facelets, Includes, Templates and Custom Tags

So I've been working with Facelets on a project recently and had to understand the differences and similarities between includes, templates, compositions, custom tags and define/inserts.  Jacob Hookom made a great blog post about this.

An include is self-explanatory, it is as if the included code was right there in the including page.  This applies to all variables and backing beans as well.

A composition lets you compose a section of html with a template and defines/inserts.  More specifically, a composition can use a template for the majority of the structure and then make some defines to "fill in" the specifics of the template.  The define is matched to the corresponding insert (they have the same name attribute).

A custom tag lets you easily reuse a composition.

What I've taken to doing is using a custom tag that has some inserts in it, so I can just use the tag and a few enclosed defines to create what I need.  This lets me keep all conditional JSTL tags (if, choose) away from the custom tag implementation.

All in all, I'm really starting to like it.