TechnoBuzz

A Techno Blog, mainly about Java

Spring Web Flow Beginner

As part my learnings of what is new with the Spring Framework, I found a nice Spring Flow 2.0 Example (with JSF and JPA).

The Spring Web Flow 2.0.2 release ( by Erwin Vervaet and Keith Donald ) comes as a separate download from the basic Spring functionality in 2.5.5.

On the Spring Web Flow (SWF) vision from 1.x to 2.x :

“[in 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
…..
The downside of this approach is it makes it difficult to apply application control logic during the view rendering phase
…..
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.
….
the ability for the SWF engine to communicate with external systems and conversational contexts over HTTP (embedding the proper flow execution callback URL in the redirect that is sent to the external system)”

Reference Guide 2.x

Also, note that getting these Spring Flow 2.x reference sample projects are easy to get a hold of. In the download of Web Flow is a projects/build-spring-webflow directory where you can run ant. It will build Web Flow along with the .war files for the sample projects (ant 1.7 and Java 5 are required to build).

There is a Struts2  plugin for Spring Web Flow called  struts2webflow

As far as further examples than the ones above, I found some web flow 2.x examples at this site spring by example.

Spring flow 1.0 showed that it could  easily integrate with struts. These  sample (1.x) applications can also be found on Java Passion Site. A good 1.x reference is the  Practical ntroduction . All the samples projects are Spring IDE projects that importable into Eclipse (see springide or plugin central for spring ide).

Here in the 1.x struts example:

Our first action in the jsp is as follows:

<A href=”flowAction.do?_flowId=birthdate”>Birth Date</A>

This action in the struts config says:

<action path=”/flowAction” name=”actionForm” scope=”request” type=”org.springframework.webflow.executor.struts.FlowAction”/>

We also bind to the Action Form:

<form-bean name=”actionForm” type=”org.springframework.web.struts.SpringBindingActionForm”/>

In the webflow-config.xml we define the flow registry:
<flow:executor id=”flowExecutor” registry-ref=”flowRegistry”/>
<!– Creates the registry of flow definitions for this application –>
<flow:registry id=”flowRegistry”>
<flow:location path=”/WEB-INF/birthdate.xml”/>
<flow:location path=”/WEB-INF/birthdate-alternate.xml”/>
</flow:registry>

Start State : the first state in the flow

<start-state idref=”enterBirthdate” />

View State: selects a view to render

<view-state id=”enterBirthdate” view=”birthdateForm”>

When the execution of the flow starts, enter the enterBirthdate state. Then select the birthdateForm view for display to the user, and pause the flow of execution until a user event happens.

Render Action: initializes the form object.

<render-actions>
<action bean=”formAction” method=”setupForm” />
</render-actions>

For view state, above Initializes the backing “form object” by invoking the setupForm method for formAction.

Note that the action was defined in the webflow-config.xml (instance of spring-webflow-config-1.0.xsd)

<bean id=”formAction” class=”org.springframework.webflow.samples.birthdate.BirthDateFormAction” />

Transition: Each View state must define a transition that leads to another state

<transition on=”submit” to=”processBirthdateFormSubmit” />

Action state: logic that needs to be executed in context of the request, once executed the result flow is returned which the flow may respond to.

<action-state id=”processBirthdateFormSubmit”>
<action bean=”formAction” method=”bindAndValidate”>
<attribute name=”validatorMethod” value=”validateBirthdateForm” />
</action>

transition on=”success” to=”enterCardInformation” />
<transition on=”error” to=”enterBirthdate” />

</action-state>

Related Links for Basic info on JSF:

Advertisements

July 13, 2008 - Posted by | J2EE

21 Comments »

  1. Will Webflow 2.0 support Struts 1.x?

    Comment by Bruce Lombardi | July 18, 2008 | Reply

  2. I like what you guys are usually up too. This sort of clever work and
    exposure! Keep up the superb works guys I’ve included you guys to my personal blogroll.

    Comment by www.mydomain.com | January 25, 2013 | Reply

  3. Paragraph writing is also a fun, if you know after that you can
    write or else it is difficult to write.

    Comment by weight loss pill review | April 26, 2013 | Reply

  4. Nice post. I used to be checking continuously this blog and
    I’m impressed! Very useful information specially the last phase 🙂 I handle such information a lot. I used to be seeking this certain info for a very long time. Thank you and best of luck.

    Comment by Gita | April 26, 2013 | Reply

  5. This post will help the internet viewers for setting up new website or even
    a weblog from start to end.

    Comment by Carl | April 26, 2013 | Reply

  6. Hi there this is somewhat of off topic but I was wondering if blogs use
    WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding expertise so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

    Comment by Fredrick | May 8, 2013 | Reply

  7. Pretty part of content. I just stumbled upon your weblog
    and in accession capital to say that I get in fact enjoyed account your
    weblog posts. Anyway I’ll be subscribing to your augment and even I fulfillment you access persistently rapidly.

    Comment by increase seman volume | May 9, 2013 | Reply

  8. Thanks for finally talking about >Spring Web Flow Beginner
    TechnoBuzz <Loved it!

    Comment by safest male enhancement | May 9, 2013 | Reply

  9. Hi, I do think this is a great web site. I stumbledupon it 😉 I’m going to revisit once again since I have book marked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.

    Comment by get fast cash loans | May 9, 2013 | Reply

  10. I am no longer certain the place you’re getting your info, but good topic. I must spend some time studying more or figuring out more. Thank you for magnificent information I was searching for this info for my mission.

    Comment by Ila | May 12, 2013 | Reply

  11. Hello mates, how is everything, and what you desire to say concerning this post, in my view its actually remarkable designed for me.

    Comment by university of australia | May 12, 2013 | Reply

  12. It’s the best time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I want to suggest you few interesting things
    or tips. Maybe you can write next articles referring to this article.
    I want to read even more things about it!

    Comment by best weight gaining supplement | May 13, 2013 | Reply

  13. I’ve been after a helpful overview on this for ages, and this has been a perfect help. I’ll be getting this tweeted for definite.

    Comment by best homeowner loans | May 15, 2013 | Reply

  14. Deffo wasnt the answer I was expecting.

    Comment by best tenant loans | May 18, 2013 | Reply

  15. Excellent post. I was checking constantly this blog and I’m impressed! Very useful information particularly the last part 🙂 I care for such info much. I was looking for this particular information for a very long time. Thank you and good luck.

    Comment by quick weight Loss center | May 27, 2013 | Reply

  16. Have not yet looked into this matter until now, I
    will do so.

    Comment by best homeowner loans | June 5, 2013 | Reply

  17. There’s nearly always a new setback waiting to be solved as soon as you’ve solved one.
    Never done eh!

    Comment by best payday loans | June 8, 2013 | Reply

  18. Not quite sure how you’ve managed to cope with it for so long.

    Comment by great loans site | June 8, 2013 | Reply

  19. Oh I see! I thought that was an optional foolish extra.

    Comment by www.crayonpedia.org | June 15, 2013 | Reply

  20. Your mode of explaining the whole thing in this post is really fastidious, every one can simply know it,
    Thanks a lot.

    Comment by http://virilityex.moonfruit.com | June 18, 2013 | Reply

  21. It is crucial that you must find out the most effective Web Design Lebanon Company to
    formulate an attractive web site to make the folks aware
    of the business services. Environmental disasters as well as a global financial crisis dominate the headlines.
    The biggest flaws with grease traps and grease interceptors are sizing,
    pumping, and odors.

    Comment by new technology news | August 7, 2013 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: