Article: Using Spring Webflow

Home

News: Article: Using Spring Webflow

  1. Article: Using Spring Webflow (36 messages)

    Spring Web Flow (SWF) is an emerging module of The Spring Framework that aims to be the best solution for the management of web application page flow, useable in any web framework. In this latest TSS article, the founders of Spring Webflow illustrate how a complex process can be implemented using the framework.

    Read Spring Webflow

    Threaded Messages (36)

  2. I would like to see the same example using Java instead of XML. Is it possible?
  3. It is possible (using Java)[ Go to top ]

    Check out the Spring WebFlow practical guide at:

    http://opensource.atlassian.com/confluence/spring/display/WEBFLOW/Practical+Guide

    It shows both Java and XML examples.

    Thank you,
    Edmon
    http://blogs.ittoolbox.com/eai/software/
  4. Keith Donald[ Go to top ]

    Yes, it is very much possible! XmlFlowBuilder is just that--another FlowBuilder implementation. It's possible to create your own custom FlowBuilders,in Java, a scripting language, a database, or sourced from a another form (perhaps a OSWorkflow definition, as a possibility!).

    Here's a quick snippet of the Bookflight flow in Java instead of API:

    public class BookFlightFlowBuilder extends AbstractFlowBuilder {
        public void buildStates() {
            addActionState("obtainTripInfo",
                action("bookingActions"),
                new Transition[] {
                    on(success(), "suggestItineraries"),
                    on(error(), "tryAgain")
                }
            );
            ...
        }
    }

    Checkout the Phonebook sample application for a complete Java-based flow builder implementation for comparsion along side a corresponding Xml version. In general, the sample applications are a great way to hit the ground quickly and to see the different features of the framework in action.
  5. I believe that Spring Web Flow is tackling a serious problem, and I like the idea behind it.

    I believe though that instead of defining a custom XML, the authors should also look at XPDL, which is the defacto XML language of defining workflows. Page Flows are Deterministic finite automate (DFAs) and XPDL workflows have some syntactic sugar that would not apply for pageflows (e.g. which user is doing what at which state, or that after a state the control can go to two states). But again XPDL workflows are DFAs, they are not of Turing machine complexity. Additionally, XPDL comes with LGPL tools for
    parsing and editing.

    The problem with web flows came up to "theserverside" forum also a few weeks ago, with the article:
    http://www.theserverside.com/articles/article.tss?l=VelocityEngine
    Where somebody defined pageflows declaratively using some features of Velocity.

    In my reply to this article I've described an XPDL based solution to this problem that could also apply here:
    http://www.theserverside.com/news/thread.tss?thread_id=32467#162532

    To close here I believe that the Spring Web Flow project should also be driven by XPDL definitions. This should be
    a very easy thing to do, the graphical editors and parsers
    for XPDL are already there, and this would be a very cheap
    solution for providing the Spring Web Flow with a UI editor.
    A UI editor is very useful if somebody is dealing with flows
    that span hundreds of pages.

    George Mournos
  6. Integration statement[ Go to top ]

    As a standalone library, Spring Web Flow is a strong fit for integration with other frameworks. Out of the box Spring MVC, Struts, and Portlet MVC integration is already provided. JSF and Tapestry integration are expected by the final release.

    What about WebWork?
  7. Integration statement[ Go to top ]

    From reviewing the WebWork Roadmap, it looks like they're considering Spring Web Flow integration for future releases. Such integration should be quite similiar in approach to how it's done for Spring MVC: a special flow action that acts as a bridge between web work and a HTTP-based flow execution manager.

    Keith
  8. SWF looks very nice!

    Two questions related to the article:

    1. The "finish" transition of the sub-flow-state "chooseSeatAssignments" points directly to the view attribute (reservationConfirmation) of the end-state "displayConfirmation" (instead of pointing to the state id). Is this a typo or should it really be like this? If it´s ok to do it like this, then what is the difference between pointing transitions to state ids and directly to view attributes?

    2. I like the way how the flow is modeled using UML state diagram. However, the desicion-state used in the example is not depicted in the diagram. Any ideas how to do this in a consistent manner or is it purposedly left out?

    /Isto Nikula
  9. Article: Using Spring Webflow[ Go to top ]

    1. That's a typo -- we went through several iterations with state naming for clarity/consistency -- looks like we didn't get one changed :-) -- the 'finish' transition of 'chooseSeatAssignments' should indeed take the flow back to the 'displayReservationVerification' state.

    2. It was just left out -- it really should be in the diagram. It'd be another state with the events (the transition criteria) being the expressions instead of a static event ID like 'success'.

    Great observations! I'll let Floyd know so these can be fixed.

    Keith
  10. Article: Using Spring Webflow[ Go to top ]

    One additional note:

    The 'decision-state' could have certainly been modeled as a action-state with a Action that makes the decision. This would've arguably translated better from the UML State Diagram, as you could better highlight how _results_ of expression evaluation are processed, rather than the expressions themselves.

    For instance, something like:

    <action-state id="isPassengerInfoRequired">
        <action bean="bookingActions"/>
        <transition on="yes" to="enterPassengerInformation"/>
        <transition on="no" to="displayReservationVerification"/>
    </action-state>

    That's pretty elegant I think--the action answers the question, the flow responds to the answer to decide where to go next. The manner in which it calculates the answer is fully encapsulated.
  11. Article: Using Spring Webflow[ Go to top ]

    Looks good. This is very similar to how JBoss jBPM models "workflows" (which are very similar to pageflows, except they are for application code, not screens, I'm sure the two could be merged though) - a state based transition with events. That shows that Spring Webflow aligns well with flow theory, which jBPM is closely connected to.

    I'm not sure this is much of a change from Struts-type flows though, except for the concept of splitting them into modules that can be reused (neat idea). There are already tools that can visualize the Struts flows in this way, it's just that the source file is harder to read than the format that is used in Webflow.
  12. Article: Using Spring Webflow[ Go to top ]

    Well, it seems that it´s easy to mix up with the naming :) I just noticed that my original mail also had the names confused: should be reservationVerification (was reservationConfirmation) and displayReservationVerification (was displayConfirmation). Anyway, your reply has the naming right, thanks.

    /Isto
  13. Could you elaborate a little bit more on the decision-state. In the given example I can see two . How does this work in general? If the first test evaluates to true then It enters into a state of executing the sub-flow. Could you throw more light on when exactly does the second get executed. From a logical perspective I can see that it enters into the subflow and transitioned to "displayReservationVerification". I am not sure that the second is even evaluated. Would really appreciate if you can write a paragraph around the decision-state with this example. Appreciate your time!! Anand
  14. Article: Using Spring Webflow[ Go to top ]

    What would be really useful is to be able to build the basic functionality from the UML diagram.
  15. Article: Using Spring Webflow[ Go to top ]

    Yes, that would indeed be a great feature. We've done all the heavy lifting to support such a feature at this point: there is a very rich definition API that a StateDiagramFlowBuilder could use to produce a fully configured Flow definition. Similiarily, there is enough information in the engineered Flow definition to then generate the Action skeletons.

    Currently two tools -- Spring IDE and Gaijin Studio (both Eclipse plugins) -- are building graphical editors atop SWF. It'd be great to see support for UML state diagrams emerge as part of the tools offering as well.

    Keith
  16. What would be really useful is to be able to build the basic functionality from the UML diagram.

    Take a look at UniMod.
  17. In another framework we used rose script to generate state java classes from rose state diagrams, it was very handy.

    /Greger Sernemar
  18. Support for XWork/WebWork?[ Go to top ]

    I saw mention for out of the box support for Struts, etc. Has anyone succussfully (and easily?) used this with the Spring/XWork/WebWork stack?
  19. Support for XWork/WebWork?[ Go to top ]

    I saw mention for out of the box support for Struts, etc. Has anyone succussfully (and easily?) used this with the Spring/XWork/WebWork stack?

    To clarify I did see Keith's statement about the WebWork roadmap. I'm curious if anyone has integrated with the current stack.
  20. Thank you[ Go to top ]

    Spring, Hibernate, Appfuse...Thank you!!!
  21. Will SWF be covered in the upcoming "Professional Java Development with the Spring" book?
  22. Spring Web Flow and Books[ Go to top ]

    Will SWF be covered in the upcoming "Professional Java Development with the Spring" book?

    I hope so. I'm providing some coverage in Spring Live. The "Advanced Form Processing" chapter (#13) has a 9-page section on Spring Web Flow that's likely to grow in the future. This chapter should be released sometime in June.
  23. So SWF is a compliment to existing frameworks. What is some one has its own framework and wanna use SWF?? Again how to use the flows or better extend the flows for EJB's. Where can i get the docs related to SWF about the patterns and approach it uses.

    Thanks
    kundan
  24. Article: Using Spring Webflow[ Go to top ]

    Checkout our the Web Flow space here:
    http://opensource.atlassian.com/confluence/spring/display/WEBFLOW/Home

    I'd recommend studying the web.flow.execution package documentation as well -- particularly the FlowExecutionManager class -- and using web.flow.mvc (Spring MVC integration) and web.flow.struts (Struts integration) as a guiding base to integrating Web Flow with your homegrown framework.

    Keith
  25. Error handling[ Go to top ]

    is the error handling going to be added?
  26. SWF seems to fall in with current thinking; namely, that
    you can't ever get away from states and state machines. State
    machines and automaton are excellent ways to model flows
    and I think SWF illustrates it very well.

    I like the idea of sub-flows and have worked on a similar
    framework myself which defines subflows as simple invocations
    of existing flows (or sub-states). The framework is older than
    SWF so I'm making the comparison in order to switch to SWF.

    One question I have though: if rendered and
    printed out, would such flows be useful to managers or
    users when presented in UML? In my experience, unless managers are somewhat technical, UML is difficult for them
    to comprehend; never mind the users, designers or customers
    that may be presented with the model too.

    Regards,

    Gary
    __________________________________________________
  27. Here are some examples where Spring Web Flow would not be appropriate:

        * Index pages
        * Welcome pages
        * Menus
        * Simple form flows (one page)

    Actually, menus may be modelled using UML statecharts also with a help of superstates. All simple states should be put into one super state. transitions from superstate to included simple states - are menu links.
  28. OTT support?[ Go to top ]

    Ah, yet another (distributed) state machine. I haven't looked into it too much, but at first glance there seems to be no ootb support for one time transaction patterns. Given that it is 2005 and I haven't overlooked it, I would find that rather frightening.
  29. YADSM[ Go to top ]

    Ah, yet another (distributed) state machine. I haven't looked into it too much, but at first glance there seems to be no ootb support for one time transaction patterns. Given that it is 2005 and I haven't overlooked it, I would find that rather frightening.

    I read the article. Although I have encountered state machines the theory since University and helped to build an implementation many years ago. I was not very impressed with this state of the art. It was not helped by the style of the English prose used. I get ever so tired of reading about how things could much be made omnipotently clear all the time, and multiple use of cliche techno-business words and phrases.

    It is kind of now so obvious when the article purports claims that if you use this particular toolkit and then invest your hard-earn working time on that other framework, then smart developers are automatically more productive and more efficient. I think here is another XML that novice developer or administrator has to support. That means another SL2 support document to write.

    Programming in Java is no longer that anymore. It is programming in Java with umpteen XML files to considered. Instead it will be XML and beyond.

    There are too many articles out there where you have to take a huge of faith. I did not get to complete reading to the end of the article. In fact, I had to put the print down. This is crass commercialism gone very bad.

    State machines have been around for a long time. I cannot see web flow being different to other Java implementations. The last one I spent time was the venerable SMC (State Machine Compiler) http://smc.sf.net/ . I am not plugging it [SMC], but just giving an example of such Finite State Machine, to give such beasties their full computer science degree title.

    I guess this will run on and on. Oh yes, I do agree with Karl Banke's critique and audit about transactions.
  30. YADSM[ Go to top ]

    Our focus in this article was to:

    1. Clearly communicate what SWF is, what problem it addresses, and how it is positioned other web frameworks.
    2. Demonstrate how to use it via example by walking-through a realistic business case.
    3. Provide a brief introduction of some of the advanced features (flow listeners, continuations etc.)

    We simply can't cover everything in one article. Would I have liked to get down into the details of the state machine implementation? Certainly! Any avid Computer Scientist would love to read that (and Pete I don't think you'd be dissapointed.). But that'd take another 10 pages. We felt our time was better spent here demonstrating key user features offered by the framework.

    Karl, what Erwin refers to is our out-of-the-box support for one-time applications transactions (duplicate submit detection, etc.). It's supported by our TransactionSynchronizer interface, with the default implementation a token-based strategy. Take a look at this interface definition--would you suggest a better name than "Synchronizer?"

    Pete, re: your concern about XML files. Nothing says you have to define your flows in XML--there is full support for Java-based flow builders, and we have sample applications that demonstrate them. There is no XML hell here.

    In regards to the back-button challenges resultant from a stateful system, yes they definitely exist. We've documented on our WIKI the issues there and the options the framework provides for addressing them out-of-the box: http://opensource.atlassian.com/confluence/spring/display/WEBFLOW/Frequently+Asked+Questions. Our support here will continue to improve.

    Thanks,

    Keith
  31. YADSM[ Go to top ]

    Karl, what Erwin refers to is our out-of-the-box support for one-time applications transactions (duplicate submit detection, etc.). It's supported by our TransactionSynchronizer interface, with the default implementation a token-based strategy. Take a look at this interface definition--would you suggest a better name than "Synchronizer?"

    No, Synchronizer is just fine, because that is what it does. The inherent problem is that you try to support a state machine and then you don't, because the state machine is essentially distributed. And if you support a certain amount of "free navigation", the concept of "continuations" does not work anymore either: Pressing the back button, say after booking a flight and resubmitting a page may never ever use a continuation or you will end up with two tickets (Which is in opinion why continuation are a bad concept anyway as soon as your flow is "doing business", while they are nice for navigating complex "logically" linked content, semantical trees, decision making systems etc.).

    What so puzzles me as that things like that are around for a long long time, see for example BEA Webflow engine (BTW, didn't they object to your name, can't believe Webflow is not a BEA trademark).

    These approaches ran into exactly the same problems and they more often than not left it to developers to solve them all over again. So in 2005, I would assume that issues like that would already be "disigned in". After all, by now, the problem should be well understood.
  32. YADSM[ Go to top ]

    Karl,

    We're hopeful we'll be able to offer a ootb TransactionSynchronizer implementation that will work with continuations (yes, obviously the flow-scoped TokenBased strategy does not), to support restoring a transactional business flow at any point in history with determination if the backing transaction has ended and thus the flow should not be restored.

    We're trying very hard to design this stuff in from the get-go -- take a look at the design of the system and let us know what you think. There is some good stuff there.

    Keith
  33. OTT support?[ Go to top ]

    Actually, there is support for one-time application transactions using the TransactionSynchronizer.

    Erwin
  34. OTT support?[ Go to top ]

    Actually, there is support for one-time application transactions using the TransactionSynchronizer.Erwin

    Erwin, unfortunately there is not. One time transaction is not (only) about that there is only one transaction running at the same time. It is about that one transaction can only be run once, once it has been started.

    Essentially it is about protected you from hitting submit more than once, hitting back a couple of times and then hitting resubmit. It is one of most crucial and most often reinvented patterns in web application programming. Your solution may help here, if and only if, you are actually enforcing the state machine on the server side.

    If you do that, however you would be in a lot of trouble for some stuff that you absolutely must be able to do in a web application environment (such as enabling usage of the back button whereever it seems feasible).

    On a slightly different note, any web application state machine must have an option of enabling client side redirects where needed (back button protection, enable reload button without resubmit etc.). I assume you do offer something like that :-)
  35. Security and Persistence[ Go to top ]

    Does anyone know if this framework is able prevent you from submitting or viewing pages that do not belong to the current state?

    And, is the flow execution id secure, since the article says that it is tracked as a hidden field by the client?

    Also can the state of the state machines be persisted and restored to support pausing and resuming?
  36. Security and Persistence[ Go to top ]

    Does anyone know if this framework is able prevent you from submitting or viewing pages that do not belong to the current state?

    Yes, a state machine by nature is very controlled. Once in a state, you can only leave by way of a valid transition. Templates rendered when view states are entered easily secured by placing them within /WEB-INF.
    And, is the flow execution id secure, since the article says that it is tracked as a hidden field by the client?

    The flow execution id is a randomly-generated MD5 encoded string by default.
    Also can the state of the state machines be persisted and restored to support pausing and resuming?

    Yes, using the pluggable FlowExecutionStorage interface. Three such persistence and restoration strategies are provided out of the box: session-based, session-continuation-based, and client.
  37. Spring Web Flow[ Go to top ]

    How different is SWF from Apache Behive (in the incubator) NetUI Page Flows?


    Srini