Ryan Lubke's Blog

Faces-config.xml? ... We don't need no stinkin' faces-config.xml!

Tuesday Mar 03, 2009

The new feature set of JSF 2.0 makes the life of the faces application developer much easier.

First, annotations.  I'm sure some of you have already read up on the annotations added in 2.0, so I'll only touch on them briefly here. 

  • ManagedBean (this includes ManagedProperty and the scope annotations)
  • FacesConverter
  • FacesValidator
  • FacesComponent
  • FacesRenderer
  • ResourceDependency
  • ResourceDependencies
  • FacesBehavior
  • ListenerFor
  • ListenersFor
In particular using ManagedBean, FacesConverter, FacesValidator, and FacesRenderer allows the developer to skip editing the face-config.xml.

The other common complaint with the faces-config.xml has been with navigation rules.  To ease the pain there, we've added implict navigation. 

Let's start with a simple example of this feature:

    <h:commandButton value="Click" action="nextPage"/>

Give the above, if there is no explicit rule defined in the faces-config.xml for the nextPage outcome, the default JSF 2.0 navigation handler will try to match a view on disk (i.e. nextPage.xhtml).  If found, it will navigate the user to that view.  Note that you could specify nextPage or nextPage.xhtml.

What if you want the navigation to trigger a redirect?  This can be handled as well.  Building off the example above...

    <h:commandButton value="Click" action="nextPage?faces-redirect=true" />

If the faces-redirect parameter is present and the value is true, the navigation will result in a client redirect.

So, with the annotations and the implicit navigation, it is possible to write an application without needing a faces-config.xml, but there are still cases where the configuration file is needed.

For example, localization information such as the default and supported locales, or using any of the advanced features such as ELResolvers, PhaseListeners, or any artifact that can rely on the decorator pattern (such as application factories, Application, RenderKit, etc). 

Feel free to give these features a go and don't hesitate to provide feedback on the forums or our issue tracker.

[7] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

JSF 2.0 is truly a very good initiative.

I find lot of interesting things in it now.

1. Any update on long pending bookmarkable URLs(which we currently do using SEAM). I read in one of the blogs Redhat team is working with Majorra team to fix this in final release. It will be nice if you can share some progress or when it is planned to release.

2. If you can share, any discussions with your team happening on JAVAFX integration, it currently does not have Web component, how do we plan to compete with Flex 3?

Thanks for the good work!

Posted by John on March 04, 2009 at 07:21 AM PST #

This is great news. I can't wait to finally (mostly) get rid of faces-config.xml.

Along the same lines as John's first question, is there any chance of getting the Mojarra schedule (http://wiki.glassfish.java.net/Wiki.jsp?page=MojarraSchedule200) updated? It has not been updated in almost a month and most of the dates on it have come and gone already.

Posted by Jeff on March 04, 2009 at 08:06 AM PST #

We're re-evaluating the release schedule. As soon as I have an update, I'll post about it in the blog.

RE: Bookmarkable URLs - stay tuned ;)

RE: JavaFX - nothing about this from the spec angle at this point in time, so I can't comment further at this point.

Posted by Ryan Lubke on March 05, 2009 at 11:25 AM PST #

WHAT A GREAT THING...
I REALLY HATE CONFIGURATION FILES!!!

Posted by Luigi on March 09, 2009 at 01:18 AM PDT #

Nice features, but, about navigation, I think that the Seam solution is better:

action="/page.xhtml" means redirection to page.xhtml.

I think it's much better then

action="page?faces-redirect=true"

Posted by Alberto Gori on March 19, 2009 at 04:33 AM PDT #

Great improvements!

Posted by Sascha on March 25, 2009 at 06:23 AM PDT #

This is good improvement.

But I would like to see CPU and memory optimizations, right now JSF is a headache of performance.

Posted by Ian on April 02, 2009 at 08:48 AM PDT #

Post a Comment:
Comments are closed for this entry.