JSF2, PrimeFaces, Spring Web Flow Integration Tutorial

This tutorial is here to help you understand the JSF2 front-end generated by SpringFuse.

If you have not generated a project yet, please generate one now.

The generated project is a fully functional CRUD web application. It is of a great help to learn JSF2, PrimeFaces, Spring Web Flow through a real example.

Introduction

This technical stack was chosen to develop enterprise applications. It would certainly not fit any kind of application. However, we believe it perfectly fits applications having hundreds of pages/views that rely on a database schema whose tables naturally represent the domain layer.

We have chosen PrimeFaces because the project is pretty active, the components look great and it was the first to really embrace JSF2.

JSF2 & PrimeFaces

Primefaces's integration is pretty straightforward, the generated pom.xml declares a dependency to primefaces jar file.

You can find numerous example of Primefaces components usage in the generated pages under:

JSF 2 & JBoss EL

Default EL implementation is pretty restrictive. For example your cannot invoke methods having parameters. Hopefully JBoss EL circumvents this limitation.

JBoss EL integration is easy, the generated pom.xml file declares a jboss-el dependency and the web.xml uses it.

JSF 2 & Spring Web Flow

JSF2 is great but we believe its navigation system is still poor compare to what Spring Web Flow has to offer.

Hopefully we are not reinventing the wheel here, Spring Web Flow (SWF) team has done an amazing job at integrating SWF with JSF 1 & 2.

Here are the various important generated files to look at for the Spring Web Flow integration

File/folder Description
src/main/webapp/WEB-INF/web.xml We define the 'app' Spring Mvc servlet to serve all views and handle all navigations. The faces servlet is also started but it won't serve the view.
src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml Configuration entry point for Spring MVC/WebFlow and JSF integration.
src/main/webapp/WEB-INF/spring/appServlet/controllers.xml Classical Spring MVC view mapping (not webflow view) are configured here. We also declare interceptors for these view (for example the locale change interceptor available from the homepage).
src/main/webapp/WEB-INF/spring/appServlet/webflow.xml The webflow configuration. Note that we declare some custom flow executions listeners.

JSF 2 & The Spring Framework

We also rely on Spring for:

Spring Web Flow "FlowScoped PersistenceContext" pattern

We are using a variation of the FlowScoped PersistenceContext in all the flows we generate. Contrary to SWF default behavior, the persistence context is propagated to sub-flows. Note that this will become the default behavior starting with SWF 2.3, please refer to JIRA SWF-360

JSF 2 & Spring Security

The generated application uses SpringSecurity. The login page uses a regular form to post the user credentials.

Generated Flows

Please refer to this blog entry