Mittwoch, 12. März 2008

JSF @ Work

(hosted on http://code.google.com/p/jsfatwork)

Lately I was thinking about doing a small JSF web application for my presentation "JSF@work" at
JSFDays*08 in Vienna hosted by IRIAN Solutions. The application should be easy to understand, small & support rapid prototyping for my live presentation. I ended up using the following components:
To see the application in action:
a) download the source archive from http://jsfatwork.googlecode.com/files/jsfatwork1-0.zip
b) run it using maven2: mvn tomcat:run

MyFaces, Hibernate & Spring are each proved technologies working very well, but h
ow to conflate all these libraries to a working web application? In the past questions like this caused headaches among many JSF web programmers. What's needed is a glue code that integrates the stack. That's where MyFaces Orchestra comes into play. Orchestra is a lightweight integration library that solves two of the main existing JSF issues:
  • missing extended scopes
  • missing long unit of work pattern for a better integration with JPA
Even more orchestra could be used with other Java web technologies, eg. Struts - but that's another story. Let's take a closer look at the two missing JSF concepts.

In general it's a good practice to keep the state of your beans as long as necessary but as short as possible. Therefore a scope is needed, shorter than the http session but one that can outlast more than one request. Access/Flash or Manual/Conversation scopes last in between session and request scopes.

Flash scoped beans are kept in memory for the subsequent request as long as they are getting referenced during the processing of one request. A conversation scope starts at certain defined entry views (pages) and has to be ended manually. Think of a wizard using several views to collect data from the user, whereas action "save to database" may be a valid exit point to invalidate the running conversation and it's state (see also Orchestra
ViewController pattern).