Integrating PrimeFaces with Spring WebFlow
March 21, 2010 1 Comment
I’m glad to announce that Spring WebFlow support which has been requested many times from Spring WebFlow users, has been added to PrimeFaces. In two different conferences, after my talks I was even approached by SWF users about this that they can’t use them together. Also there’re posts about this both in SWF and PrimeFaces community forums.
Main issue was SWF continuing the rendering of whole view even though PrimeFaces completes it’s partial response and calls responseComplete. As SWF deeply integrates with JSF, it uses it’s own lifecycle implementation and executes JSF view rendering itself instead of using JSF implementation’s way, missing the handling of responseComplete() case was causing this problem. Also another issue was SWF comes with it’s own StateManager implementation that misses to implement JSF 1.2’s saveView api. So how did I learn about these? Downloading source of SWF 2.0.8 and attaching it to my debugger🙂
Anyway I’ll create SWF patches for these issues but until they are resolved and a new version of SWF is out, I’ve fixed these on PrimeFaces side with plugging into SWF classes. As most of other Spring projects, SWF has an awesome support for extensions and plugins. By simply attaching PrimeFaces ViewFactoryCreator, you can start using SWF and PrimeFaces together with no problems. Here’s the configuration;
<!-- Executes flows: the central entry point into the Spring Web Flow system --> <webflow:flow-executor id="flowExecutor"> </webflow:flow-executor> <!-- The registry of executable flow definitions --> <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"> <webflow:flow-location path="/WEB-INF/flows/ppr/ppr.xml" /> </webflow:flow-registry> <!-- PrimeFaces ViewFactory Implementation --> <bean id="viewFactoryCreator" class="org.primefaces.integration.swf.ViewFactoryCreator" /> <!-- Configure FlowBuilderServices to use PrimeFaces ViewFactoryCreator --> <webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="viewFactoryCreator" />
That’s it, now SWF users can enjoy the PrimeFaces goodness as well.🙂
For deeper integration meaning to use SWF ajax JSF components and PrimeFaces components on the same page, as SWF suggests I’ve written the PrimeFaces version of SWF AjaxHandler. In this case, just following configuration is enough.
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController"> <property name="flowExecutor" ref="flowExecutor"/> <property name="ajaxHandler"> <bean class="org.primefaces.integration.swf.PrimeFacesAjaxHandler"/> </property> </bean>
This integration will be available with PrimeFaces 1.0.1 release until then nightly builds of PrimeFaces 1.0.1-SNAPSHOT should work, for JSF 2.0 and PrimeFaces 2.0.1, I haven’t added these because SWF does not support JSF 2.0 yet. I’m guessing SWF users need to wait for SWF 3.0 for that.