Saturday, July 4, 2009

Spring Webflow and JSF: Trouble with end-states

I've been using Spring Webflow 2 and JSF for some time months now and there's still one thing that bothers me (well, actually more than one, but this seems fundamental):

How do you reconcile the different approaches to state handling between these two frameworks? While Webflow makes it very easy to handle the current state of a Wizard-like pageflow that state is lost when you reach an end state. Say you have a very simple pageflow containing just three pages:
<view-state id="enter-details">
<transititon on="continue" to="check-details">
</view-state>
<view-state id="check-details">
<transition on="confirm" to="confirmed">
</view-state>
<end-state id="confirmed"/>

Using this flow with JSF you can use all the usual JSF components on the first two pages (the view states). The last page is a different story however. Since this is an end state Webflow will purge the flow state. Fine and dandy if it weren't for JSF's ugly reliance on the component tree to handle command buttons and links.

So what happens if you have a <h:commandbutton> or something similiar on your end state's page and the user clicks on that button? Well, surprise, the user gets redirected to the first page. As far as I can tell, JSF tries to find the current state but Webflow (correctly) determines that the requested flow has ended. Standard behaviour in this case is to redirect to the start page of the flow.

So on my current project we have built our site out of Webflows that are wired together using standard HTML links ("output links" in JSF parlance). Not really a nice solution but for now it works.


The drawbacks:

  • Some pages are enclosed in flows even though they aren't part of a "real" process (e.g. an overview page). Those flows don't even have natural end states.

  • You have to be extra careful not to use commandLinks, commandButtons or anything similiar on your end states' views. And this distinction between regular view and end state views makes working with templates quite ugly..

I'm still looking for a better way to mix free-style navigation with flows in JSF but so far I've come up blank.

No comments:

Post a Comment