The Spring Web Flow 2.0 Vision

Keith Donald

Spring Web Flow 2.0 M2 has just released. I am particularly excited about this release because it sets the foundation we need to realize the bold vision we have for our community for the future. In this entry, I'll explain what that vision is, and exactly what this foundation will enable. I'll also go into detail about the architecture of Web Flow 2.0, and compare it to the 1.0 version.

The Spring Web Flow 2.0 Vision

The goal of 2.0 is to evolve Spring Web Flow as a controlled navigation engine to offer significantly improved support for JavaServerFaces, flow managed persistence, and asynchronous event handling (Ajax) natively. The new Spring Faces project will build on Web Flow 2.0 to provide first-class support for JSF views in a Spring environment. In addition, Web Flow will continue to provide first-class support for Spring MVC-based views, allowing native JSF and MVC views to be used to full-power, even in the same application if desired.

* UPDATE: The vision above was updated on 1/11/08 after considering large amounts of feedback from the Spring community since The Spring Experience 2007. Based on that feedback, Spring Web Flow 2.0, scheduled to release in March 2008, will remain focused on the orchestration of controlled navigation and application transactions in a web application, usable as a complement to Spring MVC in an action-based MVC environment and JavaServerFaces in a component-based environment. When used with JSF, Spring Web Flow 2.0 can power an entire JSF-based web application as a "black box" or can be mixed with standard JSF navigation handlers that implement free-navigation requirements. 2.0, therefore, will be an evolutionary release adding first-class support for JSF and Ajax, supporting Java 1.4+, and providing full backwards compatibility with the SWF 1.0 flow definition language.

Now I'd like to go into a little more detail about the Web Flow 2.0 engine architecture, and how it compares to version 1.0. First lets start with a little 1.0 history.

A Little 1.0 History…

In Spring Web Flow 1.0, the SWF controller engine cared for one half of the web request lifecycle; the half related to request processing, often called the action phase. The other half, the render phase, was pushed off on the caller: either Spring MVC, Struts, or JSF front controllers. This can be shown in the SWF 1.0 architectural diagram below:

SWF 1.x Architecture

The primary benefit of this architecture is it makes it natural to introduce Spring Web Flow onto existing projects. Whether you are using Struts, Spring MVC, or JSF, you can plug Web Flow in to handle your more complex user interactions, and use plain controllers for the rest.

The downside of this approach is it makes it difficult to apply application control logic during the view rendering phase of the request lifecycle without resulting to front controller specific adapters. Consider, for example, the desire for a flow-managed persistence context. Such a context should be allocated when a new flow execution begins, de-allocated when it ends, and disconnected after intermediate view renderings while we wait for the user to continue. If view rendering is not under the flow's control, how do you issue the disconnect callback at the right time? Similar problems exist in the areas of exception handling, concurrency management, and security.

Another downside of the SWF 1.x approach is it requires duplication of effort to "fit" Web Flow in to some environments, particularly a JSF FacesServlet. In the JSF case, both Web Flow and the JSF implementation were fighting over control over the URLs and how to manage server-side state.

Enter Spring Web Flow 2.0

Beginning with Web Flow 2.0 M2, the entire web request lifecycle is now under the control of Spring Web Flow, including the view rendering phase. Furthermore, Spring Web Flow can now render responses using any view technology, with first-class support for Java Server Faces and Spring MVC-based views. In effect, this means SWF 2.0 is one of the few in its class that offers a unified controller model for all types of user interactions — stateless and stateful alike — with support for multiple view technologies as well. This also means the entire web request lifecycle can now be observed using native Web Flow execution hooks, allowing for security, exception handling, performance management, concurrency management, and persistence context management policies to be applied centrally at the proper points in the request lifecycle
The new SWF 2 architecture, shown running inside a Spring MVC DispatcherServlet, is shown below:

SWF 2.x Embedded Architecture

Subtle, but important difference.
As of Spring Web Flow 2.0 M2, four concrete Web Flow view handling strategies have been proven, and one to several of these strategies can be used in any one web application. Each of these strategies is highlighted in turn below:

Java Server Faces

The first view handling strategy supported is Java Server Faces. Through the Spring Faces project, the SWF engine can now act as a container for JSF and fully drive the JSF UI component lifecycle, combining all the strengths of the SWF application controller model with all the strengths of the JSF UI component model. As a result of this, we bring the following to the table for our community:

  • A Spring-centric way of configuring and deploying a Spring Web application that uses JSF. To get up and running, you deploy a Spring Web Servlet and point it at your bean definition files, very similar to how you configure a Spring MVC web app today. No faces-config.xml or any other special JSF artifacts are required. This makes it very easy for Spring users to take advantage of JSF without any of the traditional drawbacks. You can even use JSF inside a Spring MVC DispatcherServlet if you desire, when running in "embedded" mode.
  • Automatic support for POST+REDIRECT+GET pattern to prevent duplicate submits and browser warnings when using browser navigational buttons. This is possible for the same reasons: Spring Web Flow supports this pattern natively, and we have integrated JSF into our model.
  • Flow-managed UI component state. This is particularly interesting as use of JSF traditionally implies a large amount of HTTP Session state for storing the component tree. JSF component state is now fully managed as SWF FlowExecution instance state, which means how that state is stored is a function of the flow execution repository in use. This means it is possible to implement a JSF app with no session storage whatsoever. This also means session storage is never allocated for stateless or "REST-ful" interactions. It also means when session storage is allocated for stateful flow executions, the amount of storage allocated is less and the scope of that state is defined (and generally shorter in practice compared to your traditional JSF web application).

External Systems

The second type of view handling strategy we have proven is the ability for the SWF engine to communicate with external systems and conversational contexts over HTTP (though the API is protocol independent). A good example of this is what a e-shopping site might use a third-party like paypal for. Lets say you are guiding the user through a e-shopping experience, and as part of that experience you need to pause and redirect the user to paypal to complete a payment authorization process. Paypal, after taking over control for authorizing payment, will then call you back so you can resume the user's e-shopping experience from where you paused. This is supported generally by passing the external service a callback URL it redirects to when it is done.

Such a pattern is now supported natively by the SWF engine. To do something like this, you would simply issue an "external redirect" to the external system. Spring Web Flow now handles embedding the proper flow execution callback URL in the redirect that is sent to the external system.

Resources

The third type of view handling strategy we have proven is the ability to serve resource content (images, javascript files, css files, etc) from resource bundles such as .jar files. We have a pre-defined "REST-ful" flow installed by Spring Faces for serving Javascript and CSS resources needed by the Ext and Dojo libraries, when Ext and Dojo JavaScript widgets are rendered by Spring Faces JSF components.

Spring MVC Views

Finally, the fourth type of view handling strategy we have proven out is the ability to serve Spring MVC-based views. This allows existing Spring MVC view templates to work as they always have with Web Flow 2.0, which is important for our existing Spring MVC and Web Flow users.

Conclusion

This post provided a high-level overview of the goals of the Spring Web Flow 2.0 release, and the architectural groundwork laid in the recent Spring Web Flow 2.0 M2 release. Watch for follow up entries that highlight the key new features in M2, and the new features we are busy implementing now for M3. Jeremy Grelle, lead of the Spring Faces project, particularly has a lot exciting to talk about regarding the new JSF and Ajax support!

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • TwitThis
 

30 responses


  1. This all sounds pretty exciting…

    I do hope that the SWF AJAX functionality finds it's way into Spring MVC, or that the AJAX functionality can be used in a stand-alone manner.


  2. Hi Keith,
    Congratulatins on this release !!!.
    Is there any update on flow-managed persistence context (using Hibernate) how robust it is now? and hopefully it now disconnects during view rendereing annd conencted afterwards. I saw once there was a plan to write SWF vs Seam, I am definetly looking forward to it and specially regarding the Persistance arrea because this is the only advantage of Seam over Spring family. and i love Spring :) .

    Thanks,
    Shoaib


  3. Hi,
    Sorry for type, I mean Seam vs SWF blog entry.


  4. Hi Keith,
    In the current implementation of HibernateFlowExecutionListener I can only see that you are unbinding the session and i dont see anything like Session.disconnect() on flow pause aka view rendereing and reconnect afterwards. is this going to be change in future as I believe you people have now better control over view rendereing and it is possible now

    Thanks,
    Shoaib


  5. Hi Solomon,

    In general, the "Spring way" is all about providing properly designed, open components from which solutions can be built. Towards that end, you will definitely be able to mix use of Spring Faces UI components that provide convenient Ajax behaviors with other views that are Spring MVC-based — even in the same application if you desire. Also, while we expect the ability to declare UI component tags that install rich Ajax behaviors to be a Spring Faces feature only, there is inherent support in the Web Flow 2 architecture for handling Ajax requests that is applicable even if you're using the UI toolkits like Dojo or DWR directly in the context of a traditional MVC environment. I'll let Jeremy address this in more detail when he blogs about Spring Faces. I also know several consultants within Interface21 who are having success with this approach, and will encourage them to blog about their experiences.


  6. Hi Shaoib,

    Thanks for the kind words! You are exactly right, now that view rendering is under the control of Spring Web Flow, it is natural and easy for us to issue a Hibernate session disconnect call after view rendering when the flow execution pauses. Not adding this in M2 was an oversight on our part. I am happy to report that the latest M3 nightly build will include a fix for this, addressed by http://opensource.atlassian.com/projects/spring/browse/SWF-419.

    I'm sure you'll read more about how Spring Web Flow compares to Seam in the future. We are serious about investing in and delivering the best controller model and web framework around, and competition is welcomed on that front. I appreciate your support, and your feedback.


  7. Does the swf release have support to replace the JSF Messages framework which results in messages going out of scope when Redirect-after-post is turned on?

    In the prior 2.0 milestone this was a problem.

    Regards.


  8. It looks really cool. I especially like the REST thing.

    One question. You proudly present "Automatic support for POST REDIRECT GET pattern", but what does it add to the JSF implementation of this pattern? I mean the element in the navigation rules.


  9. Hi Keith,
    Thanks for your kind reply. I have just one more thing to ask. Will this session disconnect call will be given after the view has been rendered or just before rendering. Specifically I am interesetd to know that can we load collections inside a jsp is session connected till then? (It may not be a good practice but I am curuios to know that).

    Thanks and best Regards,
    Shoaib


  10. Hi JC,

    Yes, SWF 2.0 M2 introduces a "Message Context" facility for recording messages during the course of flow execution. Yes, messages recorded survive redirects – this is managed for you by SWF. In a SWF JSF environment, messages are available to JSF via the FacesContext automatically as well, allowing standard JSF message components to work natively. See the booking-jsf example for an illustration of this.


  11. Hi Jan,

    In a SWF environement, by default Spring Web Flow will issue a redirect after every synchronous view state POST for you automatically, with no special redirect directives required. You can turn this default behavior off and specify explict redirects if you like, similiar to what you would do with basic JSF navigation rules.

    The main point to make, though, is SWF provides you a way to moduarlize your navigation rules by domain use case, and compose your application from a set of modules organized hierarchically. JSF doesn't provide such a capability with the basic navigation handler it provides out-of-the-box. Within the SWF navigation framework, support for "Always redirect after post" is provided for you by default, which is a nice convenience.

    Hope this helps!


  12. Hi again Shoaib,

    Yes, the session disconnect call happens after the view has been rendered. Yes, this gives you view lazy loading ability.


  13. I'm very interested in seeing what the Ajax integration will look like. 2.0 is gonna be great I'm sure.


  14. Hi Keith,

    First of, congratulations on the good work. Nice to see Webflow getting better and better. I like Spring and I don't want to quit it but there is really need for a stateful application controller framework (or whatever you call it ;-) ). I have been playing with this new release on a little side projet and although I'm very pleased with what I've seen so far, there are still 2 things bugging me in the jsf sample.

    1) There are still some variables defined in your flow configuration files. I though this was the *old way* according to http://blog.interface21.com/main/2007/05/08/spring-web-flow-bean-scopes-and-jsf/, that the now recommended way, which does a lot more sense to me, was to use regular Spring scoped beans. Is this feature still supported and is it still the way to go?

    2) In the sample, you get your bean references manually through the RequestContext. I guess this is a consequence of #1 but in the case you are defining your beans in a regular application context, I suppose it's possible to inject your Spring webflow beans directly?

    Would be very nice to have a sample using the new annotations 2.5 configuration support.
    Thank for your help in advance.


  15. Hi Alexandre,

    You raise some interesting points. I'll try to address them here.

    1. The notion of "flow instance variables" managed in flow scope is not the old way of doing things – the ability to do what is written about in that blog entry still exists, but that doesn't obsolete the concept of local flow variables. Personally, I prefer a form where it is very clear what my flow instance state is going to be when the flow starts. Use of the "var" element is the way you do this when defining flows in XML; in this case, a "var" declaration is analagous to declaring class member variable in Java.

    Now, the reason you see some RequestContext lookups of flow variables by their name in the sample is because of various limitations in the current xml flow definition language. We are addressing these limitations in two ways for M3: first, we are enhancing the xml flow definition syntax to be capable of invoking arbitrary methods on beans *in any scope* in a concise manner. Second, we are introducing a POJO flow definition capability as a complete alternative to xml-based flow definition, where you get the full power of Java and Java-based dependency injection. I am excited about both of these, and the POJO flow definition approach is going to turn some heads. Expect to review the syntax and prototype examples on this blog as early as next week.

    So in summary, I do agree dependency lookups of flow variables is bad, and the only reason it's done now in the sample is because of limitations in the XML flow definition syntax which will be addressed in the next milestone. Also, you can still declare flow-scoped Spring beans that allow injection of scoped proxies into stateless services, for cases where that makes sense (which is really the point of that feature, initially described in Ben's blog entry). I think you'll see though, after M3 that case is less common than you might think.

    Also, you can expect a sample showing the new 2.5 controller annotations support in weeks time.


  16. When is the Spring Framework going to finally address REST? It's been a spring MVC bug for years now, that keeps on being postponed. Proper web architecture requires first class REST support and the frameworks are available in Java(RESTLET and Jersey) to support true REST. Sprinkling beautiful URL support is NOT REST.


  17. Hi Keith,
    Thanks for your prompt replies. I have anotjher question regarding the extended hibernate session. That is how it handles Transactions? . I you wish I can move this stuff to a forum thread as well. As still there is no docs or blogs available regarding this enhancement so I guess more and more questions will pop up :)

    Thanks and Best Regards,
    Shoaib Akhtar


  18. Hi Nadim,

    Formal REST support, including support for JSR-311 is on the radar. We expect Web Flow to be used as the dispatching infrastructure for REST resources. You can expect more information to be announced about this around the time of The Spring Experience. I agree REST is much more than just pretty URLs.

    Keith


  19. Shoaib,

    Checkout the documentation for HibernateFlowExecutionListener or JpaFlowExecutionListener. Essentially data access occurs non-transactionally until the flow enters a commit state, at which any changes to managed entities are flushed in a transaction. With that said, you can perform read-only transactional access using Hibernate during intermediate steps of a conversation by demarcating @Transactional at your service layer. This is not supported with JPA, however.

    Keith


  20. Keith,
    Thanks for reply. I have looked the javadocs and wondering that Can we inject Transaction manager inside the HibernateFlowExecutionListener and use Flush mode manual?. That way we can avoid flushing the session in btw the flow execution and at the last step of flow we can flush the session ourself. And by the way it is the recommneded way by Hibernate folks they dont say that you should not use transactions 9 i know with JPA its a standard way) but with Hibernate there is almost no issue at all and that is what i believe seam is doing as personally i am against not using transaction. Can you explain why?

    Best Regards,
    Shoaib


  21. What skills and tools does a nonprogrammer (albeit one with very good computer expertise) need to write, modify and manage page flows within an application developed in the Spring framework?


  22. Keith,
    We are on the verge of beginning a large project in my team that is expected to be delivered by the end of 2008.Having decided to program the web app based on spring web flow, we now have to decide whether to being the development based on Spring web flow 1.0.5 or should we start with web flow 2.0. We now have to publish the development standards within few days.Request you to throw some light on the expected timeframe for production release of Spring web flow 2.0.Any guidance will be appreciated.

    Thanks
    Anantha


  23. Anantha,

    springframework.org says, Spring Web Flow 2.0 final is due out in March of 2008. I would suggest that you go with SWF 2.0.

    Regards,
    Paul


  24. Hi Anantha,

    Sorry for the delay in the response.

    In general, I would recommend going with Spring Web Flow 1.0.5 for now until 2.0 enters stabilization as part of its release candidate phase in February, then begin planning your 1 to 2 migration then. You can expect 2.0 to introduce a new, simplified variant of the XML-based flow definition syntax in the M4 release; however, the 2.0 series will retain full support for the 1.0.x syntax throughout to ease migration. You can also expect a 1.0 to 2.0 migration guide to be published at that time.

    An exception to this general recommendation would be if you are using Web Flow with JSF.  If you are doing this, I would recommend adopting the 2.0 line from the start, as the JSF integration approach is much improved in 2.0 than 1.0.

    You definitely shouldn\'t feel bad about using 1.0 – its solid, and the migration to 2.0 will be straightforward.

    Keith


  25. Thanks for Work, good achievement


  26. Hi Keith!!!
    Only to tell you that It's very exciting this release, has an excellent concept about the integration with AJAX and will be good use this feature by separated or in SpringMVC…
    I will be following you in your job to put more comments about this part of the Spring's portfolio…
    "Have a good hands for a good code…"
    Thks for readme and congratulations…


  27. Why can't I see?


  28. Hi Keith,
    I'm from Argentina.
    I'm student of computer engineering and at the moment I am developing my thesis. I want to work with Web Flow 2, but I don't have previous experience, for that reason I ask if:
    1- there's a "practical introduction" for the "Booking MVC" sample, just like the "Phonebook" sample.
    2- there's some kind of tutorial for WEB FLOW 2.

    Thanks,


  29. hi Keith,

    Thanks for the wonderful work you guys have done so far.
    I am a student interested in developing a portal using apache tiles,Ajax and SWF 2.

    I am a fresher using SWF 2.There are no sample examples from a portlet perspective.Do you plan to release some samples of these sometime soon.

    Regards
    Rob Gonsalves


  30. Hi Keith
    Your design pattern and in general the design about finite state seems
    to remind me about Routh Horowitz theory on control systems where
    he actually decides based on formula known as Routh Horowitz criterion the efficieny of control systems.
    You might have a look into this for the spring webflow from this aspect.

4 trackbacks

Leave a Reply