del.icio.us Digg DZone Reddit StumbleUpon
Tutorial: Build a Shopping Cart with Spring Web Flow 2.0 - Willie Wheeler
« Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Next »

Creating a Simple Flow: Flow Definition File and JSPs

We'll now add a SWF flow definition file, update our original home page JSP, and add a new JSP for registering as a new customer.

The flow definition file

Here's a definition for our first flow, which will be a bare-bones registration process. We'll add more flows to the application but this is our starting point just to get SWF working. You'll need to create a directory /WEB-INF/flows, and then add the following flow definition file to that directory, naming the file register.xml.

Code listing: /WEB-INF/flows/register.xml
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/webflow
    http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    
    <!-- By default, the first state is the start state. -->
    <view-state id="register" view="account/registerForm">
        <transition on="submitRegistration" to="accountAdded"/>
        <transition on="cancelRegistration" to="cancelRegistration"/>
    </view-state>
    
    <end-state id="accountAdded"
        view="externalRedirect:contextRelative:/home.do"/>
    <end-state id="cancelRegistration"
        view="externalRedirect:contextRelative:/home.do"/>
</flow>

Here we have a single state, called a view state, and all it does is show us the hardcoded JSP that we created earlier. We're identifying the state itself as register, and the logical view name associated with this view state is account/registerForm. This is the name that the view resolver we defined in the Spring app context file will map to a physical location; in this case the physical location will be /WEB-INF/jsp/account/registerForm.jsp.

By default, SWF interprets the first state in the file as being the start state, or entry point into the flow. There must be exactly one start state. The flow itself is called register (this is because we've named the flow definition file register.xml). As it happens we've also named the first state register though there's no requirement for the start state to have the same name as the flow.

I've defined a couple of transitions out of the register state. One transition, submitRegistration, responds to registration submission events on the user interface, such as the user clicking a submit button on a registration form. The other transition, cancelRegistration, responds to cancelation events on the UI, such as the user clicking a cancel link. Each of these transitions leads to another state in the flow. In this case, both of the transitions lead to end states, which are exits out of the flow, but transitions can lead to other view states (or even other sorts of state) as well. As shown there can be multiple end states for a flow. Here my end states happen to be doing the same thing; they're redirecting the user to a context-relative (as in relative to the servlet context) path /home.do, which you will recall is just the home page. There are some other relativizations you can do as well:

Relativization Example
Servlet mapping-relative externalRedirect:/hotels/index
Servlet-relative path externalRedirect:servletRelative:/hotels/index
Context-relative path externalRedirect:contextRelative:/dispatcher/hotels/index
Server-relative path externalRedirect:serverRelative:/springtravel/dispatcher/hotels/index
Absolute URL externalRedirect:http://www.paypal.com/
Table 1. Relativizations for externalRedirect.

Anyway we're doing the context-relative redirection in this case. This is how we jump out of SWF and return control to the application. (Or how we return control to a calling flow, but we'll get to that.)

The JSPs

Now let's revisit our home page JSP. It's still pretty similar but I'm adding a registration link.

Code listing: /WEB-INF/jsp/home.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html>
    <head>
        <title>Products for Geeks - GeekWarez</title>
    </head>
    <body>
        <h1>Welcome to GeekWarez</h1>
        
        <div><a href="account/register.do">Register</a></div>
    </body>
</html>

The registration link takes us into the register flow, since the last path segment is register.do. In our Spring app context we told the flow registry about register.xml, so SWF will know to map requests for /account/register.do to the register flow.

Now we need a registration form. The following page is our current version of a registration "form", but as you can see it isn't really a form at all (yet). It is just a couple of links:

Code listing: /WEB-INF/jsp/account/registerForm.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html>
    <head>
        <title>Register - GeekWarez</title>
    </head>
    <body>
        <h1>Register</h1>
        
        <div>
            <a href="${flowExecutionUrl}&_eventId=submitRegistration">Submit</a> |
            <a href="${flowExecutionUrl}&_eventId=cancelRegistration">Cancel</a>
        </div>
    </body>
</html>

The point of the two links is to give the user a way to generate submitRegistration and cancelRegistration events. We saw in the flow definition that these two events trigger state transitions. Of special importance is the URL for each of these links. Notice that by using ${flowExecutionUrl}, we're still pointing the user at the same /account/register.do servlet path. That's because we're still working within the register flow. The ${flowExecutionUrl} URL includes an execution HTTP parameter whose value is a key that SWF uses for flow-tracking purposes. In addition we add an _eventId parameter that we use to drive state transitions. The event IDs are what we're referencing when we define transitions in the flow definition file.

So really so far all we can do at this point is move back and forth between the home page and the registration page, but we're doing it with Spring Web Flow.

Milestone 2: Spring Web Flow is Working

Point your web browser at

http://localhost:8080/mycart2/home.do

making any adjustments you need to make for the port or application context. Also note that the context is now mycart2 instead of mycart1 like it was in the first version of the code. If you're able to click back and forth between the home page and the registration page, then congrats, Spring Web Flow 2.0 is working! Celebrate!

Social bookmarks: del.icio.us Digg DZone Reddit StumbleUpon
« Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Next »

Comments (138)

this works only if You are using Tomcat 6.

Tomcat 5.5 and before don't support Unified Expression Language (UEL)
By Florian Rissner on May 16, 2008 at 9:26 AM PDT
Hi Willie,

Nice article, and very helpful.

I have a question,
I have been using spring-webflow-1.0.5.jar and on upgrading it to spring-webflow-2.0-m3.jar i get:

WARNING: Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

Why am i gettin this error on upgrading th jar?
Any clues?
By Deep Edward on May 19, 2008 at 9:19 PM PDT
Hi Edward. Nice to see you over here. (I recognize you from the Spring forums.) I'm just taking a guess here but it looks like you need to update the schema location in your app context file to point to the new SWF 2.0 schema instead of the old 1.0 schema. The schema location is defined on your <beans> element, at the top of the file. Also I would recommend using 2.0 GA instead of 2.0 M3 since there are definitely differences between 2.0 M3 and 2.0 GA. Good luck.
By Willie Wheeler on May 19, 2008 at 10:25 PM PDT
FYI, the schema location is

http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd

which is exactly the same as the 1.0, but with a 2.0 instead.
By Willie Wheeler on May 19, 2008 at 10:28 PM PDT
Yes,

I tried posting it in your site first, but 'twas throwing some exceptions.

Will ask you when I come across any doubts here itself :)

DeepEdward
By Deep Edward on May 24, 2008 at 6:26 AM PDT
Beautiful tutorial -- many "Ah Ha!" moments. Everything you show works like a charm (except the SiteMesh filter didn't work for me, but I just took it out like you mentioned).

I would really like to see a working example with Ajax in SWF 2.0. The reference guide material is a bit sketchy...

Thanks!
By cmontgomery on May 24, 2008 at 6:27 AM PDT
Hi Willie,

Am back, and I have a question.

It is regarding <form:checkboxes> / <form:checkbox> where I have an issue.

In my page i have multiple checkboxes. I retrieve the list and display the list of checkboxes(using <form:checkboxes>). Now as this is list of objects to which I need to bind the value, how do I bind a particular checkbox to an object, in which I have the property?
I tried binding the property but it does not bind.
Any solution?
By deepEdward on May 30, 2008 at 1:16 AM PDT
HI I Get this error when I try to run it ...
java.lang.NoClassDefFoundError: org/springframework/core/NamedThreadLocal

I'm using spring 2.5.1 and tomcat 5.5. Also in tomcat 6 it's not working
Can u please explain why I get this error
By Dilan on May 30, 2008 at 3:45 AM PDT
Use the Sprin jar 2.5.4.
This file is has the required file.
By DeepEdward on May 30, 2008 at 5:06 AM PDT
Hi Deep. I don't have an answer for you (sounds like it works in Spring MVC but not SWF 2.0.1?) but I'm posting the URL to your thread on the Spring forums.

http://forum.springframework.org/showthread.php?p=183555#post183555
By Willie Wheeler on May 30, 2008 at 7:16 AM PDT
Hi Willie,

How are you doin?

Got one doubt here..
I am using webflow version 1.0.5.
I have a situation where I need to make use of edit pages.

In this case, when the user clicks on a button(say, edit) which fetches the data from the db and then navigates to the edit pages.
On fetching the whole object from the db, how do I set it to my commandObject so that the fields in the pages are binded to the respective values contained in the object fetched from the database.

Please give suggestions,
DeepEdward
By deepEdward on Jun 12, 2008 at 6:19 AM PDT
I haven't used SWF 1.x so I can't speak to that specifically, but in SWF 2 you would use the model attribute on the <view-state> element to specify a model object that you want bound to the form. Then you could use an <on-start> element in your flow to load up the appropriate model object. Here's an example:

<flow ...>
<input name="accountId" required="true"/>
<on-start>
<evaluate expression="accountService.loadAccount(accountId)" result="flowScope.account" />
</on-start>
<view-state id="editAccount" model="account">
...
</view-state>
</flow>

The hotel application that comes with SWF 2 has an example of this. See booking-mvc\src\main\webapp\WEB-INF\hotels\booking
By Willie Wheeler on Jun 22, 2008 at 10:49 PM PDT
Just saw something in the SWF 2.0.2 reference manual that helped me understand better the first comment by Florian Rissner.

@Florian: You are right that Tomcat 6 comes with el-api.jar. If you are running Tomcat 5.5 you'll just need to provide an EL dependency (like OGNL) yourself.
By Willie Wheeler on Jun 24, 2008 at 2:02 AM PDT
I cannot get the example to work. I'm using Tomcat 5.5 with OGNL 2.6.9. WebFlow v. 2.0.2-RELEASE and Java 1.5 currently.

The /WEB-INF/jsp/account/registerForm.jsp gets rendered, but it still contains: ${flowExecutionUrl} instead of the real URL.
By Patrick Gebhardt on Jun 24, 2008 at 9:14 AM PDT
OK, I'll take a look at that this evening and let you know what happens.
By Willie Wheeler on Jun 24, 2008 at 9:22 AM PDT
Small update:
<%= request.getAttribute("flowExecutionUrl") %>
works.

You can contact me with my email too, its not displayed, but i guess you may have access to it, if not, its firstname.lastname@gmail.com (replace first/lastname accordingly)
By Patrick Gebhardt on Jun 24, 2008 at 10:08 AM PDT
Hi guys. So I didn't dive too deeply into this, but I tried deploying to Tomcat 5.5.26 and saw what you're talking about. Basically the problem is that Tomcat isn't evaluating the JSTL EL. That can be fixed by adding the following declaration to the beginning of the JSPs:

<%@ page isELIgnored="false" %>

There's probably a way to make Tomcat do that without having to modify all the JSPs but like I said I didn't look too deeply into it.

I'll fix mycart3.zip right now. Thanks guys for pointing this out.
By Willie Wheeler on Jun 24, 2008 at 11:18 PM PDT
It works for all JSP files, if you put the following in your web.xml:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
</jsp-property-group>
</jsp-config>
By Patrick Gebhardt on Jun 25, 2008 at 5:10 AM PDT
The requested resource (/SpringShoopingCart/account/&_eventId=submit) is not available.
This error is appear when I press od the link submit i the page registrationForm.jsp
Where to change some of the conf. files to me it possible to run.
By Josifov Gorgi on Jun 27, 2008 at 5:43 AM PDT
Hi,

I am trying to upload a file using spring webflow2.0.2.

I get the following exception(see the post on spring forum, http://forum.springframework.org/showthread.php?t=54466)

When i do the upload in spring mvc it works fine, but the same does not work in webflow.It seems that the apache commons-fileupload jar used for file upload tries to fetch the same file and throws a FileNotFoundException.

Any ideas Willie how to solve this.
By deepEdward on Jul 2, 2008 at 8:45 PM PDT
Hey there,

I'm having buid problems at the second step of the tutorial. When I run Build in Ant it shows the following error error: error reading C:\myCart\WebContent\WEB-INF\lib\spring-binding-2.0.2.jar; error in opening zip file
[javac] 1 error
I tried also with different spring-binding -2.0.0 but still no joy.
Please advise...
By Luke on Jul 20, 2008 at 3:35 AM PDT
To me it looks like a corrupted JAR, but I don't understand why you would get it for both JARs. Did you try opening the JARs (e.g. with the jar tool from the JDK, or with WinZip, etc.) to see if you could actually open them?
By Willie Wheeler on Jul 20, 2008 at 9:52 AM PDT
Hi Willy,

Thanks for reply. The files seem to be corrupted and cannot be opened in any way. Moreover I was trying to get new ones but unfortunately I could not find them on the web. Could You please send me those 2 files spring-binding and spring-js on my email luke_g@poczta.fm. Could I possibly ask You for Your email? I am pretty new to that stuff and I would appreciate some more help. Thanks one more time.
By Luke on Jul 21, 2008 at 10:38 AM PDT
@Luke: You will need to download them from the Spring website:

http://www.springframework.org/download

You'll see that there are some downloads for Spring Web Flow. The JARs you need are included with that.
By Willie Wheeler on Jul 21, 2008 at 5:20 PM PDT
Hi Willie,
Thanks for the article. I am very new to Spring and WebFlow. I am having a problem getting the mycart3 working. Unfortunately, I cannot download it to my machine so I have to re-type it. When I try to bring up the home.do page I end up getting a null pointer exception in CartController. It looks like the cartService is null. Looking through the files, I cannot find out where this should be set up. What am I missing?
thanks
By Tom on Aug 19, 2008 at 9:36 AM PDT
Hi Tom. Sounds like you aren't injecting the service bean into the controller. Check your application context file. I don't remember for sure but I believe I'm doing component scanning (using <context:component-scan>) in the Spring config. Make sure that you are component scanning the service bean, and also that the service bean has the @Service("cartService") annotation so that the component scan can pick it up.
By Willie Wheeler on Aug 19, 2008 at 1:37 PM PDT
Hi Willie,

Good tutorial! A few comments:

1) You should make mention in the article that there are some additional dependencies for mycart3.zip, like you did for mycart1.zip and mycart2.zip. Specifically, the user needs to copy 4 additional JAR files into their WEB-INF/lib directory:

1. cglib-nodep-2.1_3.jar
2. jstl.jar
3. standard.jar
4. sitemesh-2.3.jar (from http://www.opensymphony.com/sitemesh/download.action)

This is mentioned in the mycart3.zip readme.txt file, located in the mycart3\web\WEB-INF\lib directory.

2) In the "Subflows" section of the article, you mention that login flow is both a top-level flow and a subflow. However, in the checkout.xml file, you use a view-state tag instead of a subflow-state tag (like you do for the add to cart and register subflows). Why?

3) The EL used in the JSPs is the JSP-EL (which you refer to as the JSTL EL and earlier as the Unified EL), whereas the EL used in the flow definition files (e.g., checkout.xml) is the OGNL. This is not clear in the article, where it sounds like you're using OGNL in both cases.

Thanks.

- Matt
By Matt on Sep 4, 2008 at 4:40 PM PDT
Hi Matt. Thanks very much for taking the time to submit your suggestions and questions. Let me answer them in turn:

1) Yup, agreed. I put the fix in.

2) I wasn't very clear in the article on that point. The idea was that I was just faking the login form from the checkout UI, meaning that if you submit any credentials then it just carries you to the next state. But in retrospect that's a silly thing to do since the whole point of the subflow section is to show how to launch subflows, and it's too easy for people to walk away thinking that's an example of how to do them. (As you mention I did provide a couple of genuine subflow launches but login wasn't one of them.) Anyway I updated the checkout.xml and viewcart.jsp files to use an actual subflow, and I updated the mycart3.zip download as well.

3) You are right--the JSP EL originated in JSTL but it eventually made its way into JSP 2.0 generally (even if you're not using JSTL). I changed the reference to JSTL EL in the article to JSP EL instead.

As far as United EL goes, I don't believe I referred to JSP EL as United EL, though if I'm mistaken please let me know as that would not be correct. United EL and OGNL are two options that are available to you in the flow definition files, as you mention. I am using OGNL only in the flow def files and I'm not using United EL at all.
By Willie Wheeler on Sep 6, 2008 at 11:42 AM PDT
Hi Willie,

Great Tutorial!!!

I was wondering how would you implement a login mechanism with this example?

Do you have any sample code.I've tried to do that but it is not quite working. Any suggestion would be appreciated.
By Gerald on Sep 7, 2008 at 3:34 PM PDT
Hi Gerald. Glad you liked it. I don't currently have any sample code with a real login mechanism, but if you download SWF it comes with a hotel booking sample application that does include it, using Spring Security.
By Willie Wheeler on Sep 7, 2008 at 3:37 PM PDT
Thank Willie.

I've tried the example in the booking aplication and it worked but what I'm trying to do is twofold:
1. first have a login page for members where upon success, they will go to the member home. I've implemented that with Spring Security and it worked perfectly.

2. Second, have a login page during a checkout process where upon success, the account information is loaded from the database. That second step is where i'm stuck.

Any idea on how that functionality could be implemented?
By Gerald on Sep 8, 2008 at 9:39 AM PDT
Hi Gerald. If your login process were to load your account information (username, first name, last name, e-mail, etc.) onto the HTTP session upon a successful login, would that give you what you needed? (Don't you need that for the member home as well?)
By Willie Wheeler on Sep 8, 2008 at 12:18 PM PDT
Willie,

I will need that functionality for the member home as well but Spring security won't let you specify more than 2 views for the login page (I may be wrong but i've tried it and it is not working for me ). My problem is that my only option now is to specify only one success view upon a login sucess( which is the member home page) but i have two place of login in my application(the second one is the checkout login which has a billing address page as the success with the billing info getting loaded from the database) .
Any ideas?
By Gerald on Sep 8, 2008 at 11:47 PM PDT
With respect to loading account information, take a look at implementing a custom UserDetailsService. It's actually the expected approach rather than an unusual approach, and it's pretty easy to do since it involves implementing only a single method that returns a custom UserDetails implementation. Usually that UserDetails implementation would be a wrapper around your user account model. See my post here

http://forum.springframework.org/showthread.php?t=59871

for some code examples, though in that code I neglected to mention that I'm not really handling roles yet. (It would be easy to do though.)

As far as having multiple login targets (one for a direct login that drops you into the member home, and one for a checkout process that allows you to continue down the flow), that is a good question. I will have to look into that as I have *precisely* the same need on my own website.
By Willie Wheeler on Sep 9, 2008 at 7:24 AM PDT
Thank you very much, Willie. By the way,when is the book coming out?
By Gerald on Sep 9, 2008 at 2:04 PM PDT
Hi, I get the following error when I try to open the url ...../home.do: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/webflow-config]
Offending resource: ServletContext resource [/WEB-INF/mycart-servlet.xml]

Can you help me?

Thanks
By Edu on Sep 10, 2008 at 1:04 AM PDT
Sorry, I reply myself: I have not included the dependencies "spring-webflow" and "spring-binding". Regards.
By Edu on Sep 10, 2008 at 1:24 AM PDT
I am unfortunately getting stuck at step one - deploying the app without using web flow. I use tomcat 5.5, but included ognl-2.6.9.jar in my lib folder. In netbeans I right-click on the project and click deploy. When visiting localhost:8180/mycart1/home.do, I get the following exception:
javax.servlet.ServletException: Servlet.init() for servlet mycart threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)

root cause

java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
java.security.AccessController.checkPermission(AccessController.java:427)
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1662)
java.lang.Class.checkMemberAccess(Class.java:2125)
java.lang.Class.getDeclaredMethods(Class.java:1762)
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:429)
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:412)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.findAutowiringMetadata(AutowiredAnnotationBeanPostProcessor.java:299)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(AutowiredAnnotationBeanPostProcessor.java:179)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:745)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:448)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
java.security.AccessController.doPrivileged(Native Method)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:402)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:316)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:282)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
javax.servlet.GenericServlet.init(GenericServlet.java:211)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:115)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)


Any idea what might be happening there? I did modify 04webapp.policy to grant permissions to this project.

Thanks.
Marco
By Marco on Sep 10, 2008 at 7:49 AM PDT
@Gerald: Book should be out around mid-2009. We just got started on it.
By Willie Wheeler on Sep 10, 2008 at 8:42 PM PDT
nice article,and very helpful
i have question,org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/webflow-config]
Offending resource: ServletContext resource [/WEB-INF/mycart-servlet.xml]
By liangwenquan on Sep 11, 2008 at 12:52 AM PDT
hi, Edward
great article ,i'm new in webflow
- i try to run your aplication, and when i try to go to the register link in home.do
i got this execption,

java.lang.NoSuchFieldError: WEB_APPLICATION_CONTEXT_ATTRIBUTE
org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:48)
org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:169)
org.springframework.webflow.engine.ViewState.render(ViewState.java:257)
org.springframework.webflow.engine.ViewState.resume(ViewState.java:216)
org.springframework.webflow.engine.Flow.resume(Flow.java:551)
org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:263)
org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:153)
org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:173)
org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)



i'm using netbeans 6.1
jdk1.6.0_06
spring-webflow 2.0.3
spring-framework 2.5.5
tomcat

i think the problem is whit the view in the flow but,("<view-state id="register" view="account/registerForm">")
but i don't figure out which is the mistake, i apritiate your help.
By seba on Sep 11, 2008 at 10:33 AM PDT
Hi Willie,

Do you know what this may be ?


SEVERE: Servlet.service() for servlet ecommerce threw exception
ognl.NoSuchPropertyException: org.springframework.webflow.engine.impl.RequestControlContextImpl.shoppingCart
at ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:122)
at org.springframework.webflow.expression.WebFlowOgnlExpressionParser$RequestContextPropertyAccessor.getProperty(WebFlowOgnlExpressionParser.java:118)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)
at ognl.ASTProperty.getValueBody(ASTProperty.java:92)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at ognl.SimpleNode.getValue(SimpleNode.java:210)
at ognl.ASTChain.getValueBody(ASTChain.java:109)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at ognl.SimpleNode.getValue(SimpleNode.java:210)
at ognl.Ognl.getValue(Ognl.java:333)
at org.springframework.binding.expression.ognl.OgnlExpression.getValue(OgnlExpression.java:81)
at org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:76)
at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145)
at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:101)
at org.springframework.webflow.engine.State.enter(State.java:194)
at org.springframework.webflow.engine.Flow.start(Flow.java:541)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:351)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:222)
at org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:133)
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
By Gerald on Sep 13, 2008 at 10:54 AM PDT
Regarding the various stacktraces that people are posting, no, sorry, I haven't seen any of those, so I can only guess here.

@liangwenquan: Make sure you have the required JARs on the classpath.

@Gerald: I'm assuming you're writing your own EL in the flow definition files? If so just make sure that any properties you're referencing with the EL actually exist.
By Willie Wheeler on Sep 14, 2008 at 8:45 PM PDT
This is really of great help to get a tutorial on Spring Web Flow 2.0. This is a nice and simple to understand tutorial. Thanks.
By Shantanu Banerjee on Oct 2, 2008 at 10:41 AM PDT
Hi Willie,

I am using Spring Web Flow and have spring session scoped bean (Shopping Cart)

How do I remove the scoped session variable(e.g shopping cart) after the customer finish the flow?

In MVC, we would do something like
request.getSession().removeAttribute("shoppingcart" );

Any hint?

Thanks,
By Gerald on Oct 17, 2008 at 7:57 AM PDT
hi, Edward

I did not have any issues with mycart1. While trying to run mycart2, I am getting the below error when I click on the Register link on the home.jsp.
java.lang.NoSuchFieldError: WEB_APPLICATION_CONTEXT_ATTRIBUTE
at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:48)
at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:169)
at org.springframework.webflow.engine.ViewState.render(ViewState.java:257)
at org.springframework.webflow.engine.ViewState.resume(ViewState.java:216)
at org.springframework.webflow.engine.Flow.resume(Flow.java:551)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:263)
at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:153)
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:173)
at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Unknown Source)


I am using MyEclipse, jdk1.5, jboss4.2, spring 2.5
spring-webflow 2.0.3

Appritiate advice on the issue.

Thanks
Vinaya
By Vinaya on Oct 20, 2008 at 2:04 PM PDT
@Vinaya: Try updating to Spring 2.5.5 and see whether that solves the problem.
By Willie Wheeler on Oct 20, 2008 at 2:27 PM PDT
Nice precise article.

Thanks a ton.
By Nice article, and very helpful. on Oct 21, 2008 at 6:04 AM PDT
Hi,

Thanks a lot for the tip.
That worked for me.

Thanks
Vinaya
By Vinaya on Oct 21, 2008 at 1:32 PM PDT
Nice Article ,

Its working at My End,

Thanks
By Kapil on Oct 25, 2008 at 4:59 AM PDT
Hi Willie,

I am using Spring Web Flow and have spring session scoped bean (Shopping Cart)

How do I remove the scoped session variable(e.g shopping cart) after the customer finish the flow?

In MVC, we would do something like
request.getSession().removeAttribute("shoppingcart" );

Any hint?

Thanks,
By Gerald on Oct 28, 2008 at 10:43 AM PDT
Thanks a lot for this tutorial!!

I've bought Pro Spring 2.5 a few weeks ago but somehow I didn't get their webflow example working. It's like they just copy pasted some parts of the Spring documentation or so.

I'm considering buying your Spring in practice book as soon as it gets released because I've got a feeling it will be much more reader friendly.

Greets
By Jochen Szostek on Oct 30, 2008 at 4:05 PM PDT
Hi all ,

I have got a problemin running tis sample mycart3.zip . I am using tomcat 6, jdk 1.6 . I go the zip file extracted it configured in my eclipse add the jar files and dependency jars. But i not working , i am getting confused from the jar file version.

I am getting errors in annotation where ever the @override is mentioned in the eclipse - i am not able to compile it. what could be the problem .

Thanks in advance for you help
By Syresh on Nov 10, 2008 at 12:03 PM PST
Reposting -due to typo error.

Trying to deply and run mycart3.zip example. Do have all the jars thats metioned, but still i am not able to compile the sample code base. I am not familier with annotations - any help here would be helpfull. I am new to springs and SWF.
By Syresh on Nov 10, 2008 at 1:57 PM PST
@Syresh: Even though you have JDK 1.6, I wonder if you have your Eclipse project set to JDK 1.5. In Eclipse, go to Window > Preferences > Java > Compiler and look at what JDK compiler compliance level you're using. You should set it to 1.6 if you're not already doing so.

Alternatively, you can just get rid of the @Override annotations. That particular annotation works differently in JDK 1.5 than it does in JDK 1.6. It isn't essential; the intent is to prevent the developer from getting the signature wrong when overriding a method.
By Willie Wheeler on Nov 10, 2008 at 4:21 PM PST
Willie,

Thank you for the easy to understand tutorial.
I believe line 41 on page 6 should read:
"<!-- This is where we go when the subflow returns. loginOk is"

Keep up the good work,
Alberto
By Alberto Armenteros on Nov 12, 2008 at 3:56 PM PST
@Alberto: Ayep, foiled again by cut-and-paste. Thanks for the catch; I'll fix that next time I do content edits...
By Willie Wheeler on Nov 13, 2008 at 12:22 AM PST
Very nice tutorial! Worked fine!
What should I do to make the login (security) working?
Any hint or tutorial page?

Thanks a lot.
By sistronda on Nov 18, 2008 at 11:57 AM PST
Thanks sistronda! As for the login, yeah, somebody else was asking about that as well. I haven't actually gotten around to looking into integrating SWF with Spring Security so I can't yet provide much information on that. I think the hotel booking sample app that comes with SWF addresses it though so you might check that out.
By Willie Wheeler on Nov 18, 2008 at 12:30 PM PST
Congratulation for the nice article. I was trying to integrate the example with database. I created a ProductService class and pulled the products from database and listed on a home page. Now I should I pass that product listed on the page to WebFlow. My controller looks like this.

@Controller
public class HomeController {

@RequestMapping("/list.do")
public ModelMap doHome() {
ModelMap model = new ModelMap();
model.addAttribute("products", productService.findAll());
return model;
}
@Autowired
ProductService productService;

}
By cropper on Nov 21, 2008 at 4:49 AM PST
@cropper: The code you include should result in products being passed over to the JSP (assuming that your productService.findAll() actually returns a list of products, assuming that you're mapping the call to a logical view and that in turn is mapping toward a physical page, etc.). Can you elaborate a little more on the problem you are having? It is not clear from your post.

Incidentally, after I wrote the article, I found out (from Keith Donald, coincidentally--he did a presentation at our local JUG) a better way to handle the model. You can do this:

@RequestMapping("/list.do")
public void doHome(Model model) {
model.addAttribute(productService.findAll());
}

There are two things going on here. First, Spring Web MVC automatically creates a Model instance and passes it into the method, which saves two repetitive lines of code. Second, Spring Web MVC chooses a conventional attribute name if I don't provide one, which here would be "productList". There are some other things like this (such as conventions around request mappings) but the two above are pretty quick and easy.
By Willie Wheeler on Nov 21, 2008 at 8:30 AM PST
That was neat. Thanks for that information. Sorry for the ambiguity This is what I am trying to do.

1. Populate a home page with list of Products and Promotion and when the user selects a product , that should take him/her to the addToCart flow action. This home page listing is not part of the webflow it is simple spring mvc JPA jsp view.


What I am finding difficult is to instantiate CartService from my home page mvc controller HomeController and pass the selected product to the shoppingCart.addItem method.
By cropper on Nov 21, 2008 at 9:01 AM PST
@cropper: The sample shopping cart app that comes with the article does exactly what you're saying (well, without a Promotion), so I'm still not totally following where you're having trouble... ?

The sample app instantiates CartService in the IoC container, not in the HomeController. After creating it, though, the container injects the CartService into the HomeController. I'm doing this through component scanning and autowiring.

Also, in the sample app, the home page is not part of the web flow, and the addToCart.do part is (and it sounds like that's what you want). Clicking on the relevant link in home.jsp passes the product ID to addToCart.do, and this in turn adds the item to the shopping cart, as specified by
the addToCart.xml flow.

I suspect I'm still not understanding you correctly though... :-/
By Willie Wheeler on Nov 22, 2008 at 8:42 PM PST
Willie,

Sorry for the communication flaw. Let me please try it again.

In your sample application the products are displayed in the home page in home.jsp by iterating the products object which is in the cartService.

In you cartServiceImpl you have manually added the products through a arrayList if I am correct.

What I am trying is load the products from the database using a productService and show it on the home.jsp instead of manual addition.
By cropper on Nov 24, 2008 at 9:37 AM PST
I think my previous post also confusing.
The simple question is how to inject my ProductService bean into the mycart-servlet.xml. So that I can use this in the CartController. I know its nothing to do with webflow just spring-mvc question I think.
By cropper on Nov 24, 2008 at 6:08 PM PST
@cropper: You'll need to add a setProductService() method to the CartController, and then add a ProductServiceImpl bean to the mycart-servlet.xml file. You'll also need to make sure you have the @Service("productService") annotation on your ProductServiceImpl class if you're using component scanning and autowiring. Basically your ProductService is entirely analogous to the existing CartService so just copy what you see there. If you are just stuck, try removing the autowiring and configure the beans and their dependencies manually.
By Willie Wheeler on Nov 25, 2008 at 3:12 AM PST
Willie,

I think I am doing exactly that.

This is the result I get.
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: Session is closed!; nested exception is org.hibernate.SessionException: Session is closed!
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)


Here is my snippets.

presistance.xml
<persistence-unit name="DefaultEntityManager" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true"/>
<!-- <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/> -->
</properties>
</persistence-unit>

ProductServiceImpl

@Repository
@Service("productService")
public class ProductServiceImpl implements ProductService{

private EntityManager em;

@PersistenceContext (name="DefaultEntityManager")
public void setEntityManager(EntityManager em) {
this.em = em;
}

@Transactional
public List<Product> findAll() {
Query query = em.createQuery("select p from Product p");
return query.getResultList();
}

and in mycart-servlet.xml


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="DefaultEntityManager"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
By cropper on Nov 25, 2008 at 6:24 AM PST
@cropper: OK, now we're getting somewhere. :-)

I'm zeroing in on the "Session is closed" error message. Can you post the controller method?
By Willie Wheeler on Nov 25, 2008 at 10:03 AM PST
@Controller
public class CartController {
private CartService cartService;
private ProductService productService;
public void setCartService(CartService cartService) {
this.cartService = cartService;
}

public void setProductService(ProductService productService) {
this.productService = productService;
}
@RequestMapping("/home.do")
public ModelMap doHome() {
ModelMap model = new ModelMap();
model.addAttribute("shoppingCart", cartService.getShoppingCart());
model.addAttribute("products", productService.findAll());
return model;
}


do I have do something on the web.xml I was seeing some search on the google and it said i have to add this snippet to get rid of the session error.

<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityMana gerInViewFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

then I got no context loaded error.
By cropper on Nov 25, 2008 at 10:55 AM PST
I'm not myself a big fan of that "open session context (or entity manager, as the case may be) in view" pattern. Ideally you want to do your transaction and be done with it by the time you hit the view. (Having a larger transaction scope means increased contention. It's similar to the way you want to keep your mutex critical sections tight.)

Nothing's jumping out at me, but you can do divide-and-conquer here. Check your shopping cart and product services individually. If one works and one doesn't, you'll just need to systematically compare them to see what's going on. Anyway if you figure it out feel free to post the answer (though you're right that this isn't a Spring Web Flow issue). Good luck. :-)
By Willie Wheeler on Nov 25, 2008 at 3:16 PM PST
At Last I could make things work. It was something to do with the xml schema for the mycart-servlet.xml

if you add the bellow schema reference everything should be fine
xmlns:tx="http://www.springframework.org/schema/tx"
By cropper on Nov 26, 2008 at 10:42 AM PST
Heh, yep. You have to declare the namespace to use the namespaced configuration. :-D Thanks for posting the solution, and glad you found it.
By Willie Wheeler on Nov 26, 2008 at 10:44 AM PST
Thanks for the great article. its very helpfull.
but i didn't find these jar files.
spring-webflow-2.0.0.jar
spring-binding-2.0.0.jar
spring-js-2.0.0.jar

i dolwnloaded Spring Web Flow 2.0 framework.

can u please help me to find.

Best Regards
By mohd sajid on Dec 24, 2008 at 8:04 AM PST
I am attempting to run this tutorial in Netbeans 6.5, spring-2.5.jar, jdk 1.6 and Tomcat 6.0.18 (have tried GlassFish also).

The first example works fine, but when I try the second using the simple web flow, I get the following error:

Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 17 in XML document from ServletContext resource [/WEB-INF/mycart-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: The prefix "context" for element "context:annotation-config" is not bound.

I get the same error with glassfish also. Here are the <beans ... references that I am using:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd">


I am new to Spring, but I have run through several MCV examples without a problem. This is my first web flow example. Web flow is very exciting and I really want to use it, I just need to get through this first boot strap.

Thanks in advance
Raider
By Raider on Jan 1, 2009 at 4:47 PM PST
OK, last post was a stupid user error, somehow I left out:

xmlns:context="http://www.springframework.org/schema/context"

Adding this, got me passed the previous error. Now I am getting the following:

SEVERE: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/webflow-config]
Offending resource: ServletContext resource [/WEB-INF/mycart-servlet.xml]


My <beans ... now looks like this?

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">

I know it is January 1, but hopefully I am not the only Spring user out there.

Raider
By Raider on Jan 1, 2009 at 5:40 PM PST
@mohd sajid: Check the dist folder in the download.

@Raider: Make sure you have the necessary Spring Web Flow JARs on the classpath. When you use special schemas (like the webflow-config schema), the container needs help with knowing how to interpret the associated schema elements (like flow-executor, flow-execution-listeners, flow-registry, and flow-builder-services). In this case the problem is probably that the WebFlowConfigNamespaceHandler class isn't on your classpath.
By Willie Wheeler on Jan 1, 2009 at 10:34 PM PST
Thanks Willie, I have web flow working in Netbeans 6.5!

I had to strip out all of the spring libraries that come with Netbeans and replace them with those itemized in this tutorial. The only jar not located where this tutorial said it was, was commons-logging.jar . It is not located in (located in /spring-framework-2.5.4/jakarta-commons). I found it at:

http://www.java2s.com/Code/Jar/Spring-Related/Downloadcommonsloggingjar.htm

Thanks again, I am on to completing this tutorial...

I have developed an educational word game that is a lot of fun to play. At least that is what all of the testers tell me. Anyway, I am now building a site to sell the game and puzzles.

Initially, I was going to have someone else do the web site, but the quotes were too outrageous to believe. So, I have decided to just build it myself.

Raider
By Jerald Donaldson on Jan 2, 2009 at 1:53 PM PST
@Raider/Jerald: That is outstanding. Let me know the URL once you get it working. I'd like to check it out.
By Willie Wheeler on Jan 2, 2009 at 3:58 PM PST

Hi, a great tutorial!

I am curious as to why you went with the FlowController instead of FlowHandlers. Keith Donald says "FlowHandlerMapping was introduced in 2.0.4 [which is now recommended as a superior alternative to the old FlowController]. " in his comments on SWF-939.

I looked at section 9.5. ("flow-executor options") in the SWF Reference Guide but I didn't see anything that would explain this to me.

Thanks, Andy

By Andy on Jan 8, 2009 at 11:29 AM PST

@Andy: Thanks for your nice words about the article. I wrote the article back in May 2008, and the suggestion you mention materialized afterward. Thanks for the pointer to the JIRA ticket SWF-939 though. I will take a look at it and in all likelihood adopt the approach for the book.

By Willie Wheeler on Jan 8, 2009 at 12:03 PM PST

Hi Willie,

In the MyCart2 example, the Cancel buttons on the register and checkout pages use the following implementation in the view:

<button onclick="document.location='${flowExecutionUrl}&_eventId=cancelRegistration'">Cancel</button>

which doesn't work for me. I think it is supposed to be:

<input type="submit" name="_eventId_cancelRegistration" value="Cancel"/>

see 10.6.1 [http://static.springframework.org/spring-webflow/docs/2.0.x/reference/html/ch10s06.html#webflow-event-named-html-button] in the Reference Manual

Now, the weird thing is that when I click the button (or the href) to Cancel the registration, I am taken to the checkout page. But doesn't the flow definition say I should be taken to the home page?

By Andy on Jan 14, 2009 at 2:13 PM PST

Oops - I meant the MyCart3 example.

By Andy on Jan 14, 2009 at 2:14 PM PST

It will mycart3 work with Tomcat6 version only ,

By Murali Kaparthi on Jan 15, 2009 at 1:26 PM PST

Hi Willie, thx by the article. If you please can help I'm getting trouble with the CartController and CartServiceImpl. I'm using Ganymede, JBOSS 5.0, spring 2.5.4 and WebFlow 2.0.5. Those beans appeared on component scan but when I do home.do I just get 00:12:33,781 WARN [PageNotFound] No mapping found for HTTP request with URI [/cart-war/home.do] in DispatcherServlet with name 'mycart'.

Looks like its not injecting correctly, but I really dont know how to fix it.

I tryed to load home bean directly from context but cartService returns null in its turn.

By Ruben Trancoso on Jan 15, 2009 at 6:15 PM PST

Excellent Sample Appplication to jump start Spring webflow 2

By Chinna on Jan 16, 2009 at 5:30 AM PST

RE: Cancel Registration --> Checkout instead of /home.do

So, the register flow was being called as a subflow from checkout and I guess the FlowExecutionOutcome is being evaluated in the checkout flow well before the sub-flow's end-state @view is ever evaluated.

I suppose the @view is still necessary in case the flow is ever executed directly?

By Andy on Jan 16, 2009 at 8:08 AM PST

hi Willy,

Thanks a lot, excellent article - this is the best swing introduction level resource I have found!!

Kevin.

By Kevin McGarry on Jan 29, 2009 at 4:09 AM PST

Strange exception here (I used the name "dispatcher" and not "mycart" to the dispatcher servlet... but that's not the case): I am using WebFlow 2.0.5.

See the exception:

SEVERE: Context initialization failed org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition(Ljava/lang/String;)Lorg/springframework/beans/factory/support/BeanDefinitionBuilder; at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:385) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:158) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:97) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:411) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:338) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:332) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:266) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:236) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619)

By Paulo Pinheiro on Feb 2, 2009 at 12:36 PM PST

NoSuchMethodException usually means you're dealing with some kind of JAR version incompatibility (including incompatibility with the JDK you're using). One library is trying to call a method on another library that no longer exists. You may need to look at the source code to see what method is being called and then look whether you have the right JARs in place.

By Willie Wheeler on Feb 2, 2009 at 12:48 PM PST

I get the following warning...which I think is a description of the problem to some degree...

No mapping found for HTTP request with URI [/weboe/home.do] in DispatcherServlet with name 'weboe'

I have a feeling it's something stupid, but I re-check configuration for mycart1 a million times and can't pinpoint what's wrong. The only think I did is chanced mycart to weboe

By Alex on Feb 5, 2009 at 11:38 AM PST

Hi Very excellent article for beginners.

By bajaranglal on Mar 10, 2009 at 10:57 AM PDT

really great article ...

By Sachin Sthalekar on Mar 19, 2009 at 2:16 PM PDT

Hi Wille,

The example which you have provide is excillent. I have configured what you suggested in mycart1 and mycart2 in Tomcat 6.0. When I gave the URL which you provided it is giving error on browser:

HTTP Status 404 -


type Status report

message

description The requested resource () is not available.

Could you please suggest what needs to be done here as I am very new in Spring mvc.

By Debo on Apr 16, 2009 at 11:41 AM PDT

Hi Wille,

I did some changes in my-cartservlet.xml by adding:

I am not sure why it didn't work without specifying the above steps. Now the code is throwing NullPointerException from doHome() method of Cartontroler.java at location:

model.addAttribute("shoppingCart", cartService.getShoppingCart()); model.addAttribute("products", cartService.getProducts());

It is not able to find instance of cartService and due to that it is throwing Exception.

Need your help to resolve it....

By Debo on Apr 16, 2009 at 2:01 PM PDT

Is there a way to hide the query parameter [query string] in with spring webflow. I am using spring webflow and JSF and i need to hide the query string in the url. for example:

www.mywebsite.com/app/index.jsp?id=66

need to hide id=66

is the way to convert all the HTTP GET to HTTP POST with spring webflow?

thanks PM

By PM on May 13, 2009 at 12:44 PM PDT

Thanks for your help.

By Kenan on May 23, 2009 at 12:23 AM PDT

Hello,

I have MyEclipse 7.1.1 running tomcat 6 with mycart1 as a maven project.

The URL http://localhost:8080/mycart1/home.do results in error:

HTTP Status 404 - /mycart1/home.do description The requested resouce (/mycart1/home.do) is not available.

I am trying to use Spring Web Flow to build a shopping cart functionality.

~Yusuf

By Yusuf Arif on May 27, 2009 at 1:37 PM PDT

I am trying to deploy mycart3 and getting following exception on deploy. What could be the reason??

java.lang.NullPointerException mycart.CartController.doHome(CartController.java:18) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:421) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:136) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

By makj2ee on May 30, 2009 at 8:48 PM PDT

Nice article and very useful information. I am trying to deploy mycart3 on tomcat6. Following exception is thrown..any idea why?

java.lang.NullPointerException mycart.CartController.doHome(CartController.java:18) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:421) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:136) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

By makj2ee on May 30, 2009 at 8:58 PM PDT

Hello all,

I am a newbie to Java and Spring but have nevertheless been thrown to the wolves and put on a new project involving these technologies among others. Specifically, I have been told to learn Spring Web Flow 2.0. I found this promising tutorial, but the sample source seems to be missing either Ant or maybe Maven build files. Have I missed something obvious?

Thanks

By Frank Lautenbach on Jun 1, 2009 at 11:56 AM PDT

Thx for giving me such a good article, it is very very helpful since I a fresh of the SWF.

By chnic on Jun 3, 2009 at 8:00 PM PDT

Its a cool tutorial....its good for the beginner like me.

By Jana on Jul 22, 2009 at 2:21 AM PDT

Excellent, excellent article. It was extremely helpful and well explained. Thanks!

By Cold-Gin on Aug 13, 2009 at 4:06 PM PDT

Can anyone please explain abt spring web-flow?What is the advantage and disadvantage of this.

By shibasss on Sep 3, 2009 at 2:59 AM PDT

All questions in this site....no answers :(

By Spring User on Oct 1, 2009 at 3:21 AM PDT

Great tutorial. Something that really grinds my gear about other articles on spring webflow is that they are not focused on a single subject. They want to explain webflow in a sample project which is based on jsf, jpa, myfaces and other technologies.

By Ebrahim on Oct 26, 2009 at 11:51 AM PDT

i am getting below error at cart2.zip

[11/16/09 17:37:19:962 EST] 0000002d WebApp A SRVE0180I: [myCart#SpringCart.war] [/SpringCart] [Servlet.LOG]: Initializing Spring FrameworkServlet 'mycart' [11/16/09 17:37:19:971 EST] 0000002d DispatcherSer I org.springframework.web.servlet.FrameworkServlet initServletBean FrameworkServlet 'mycart': initialization started [11/16/09 17:37:20:049 EST] 0000002d XmlWebApplica I org.springframework.context.support.AbstractApplicationContext prepareRefresh Refreshing org.springframework.web.context.support.XmlWebApplicationContext@186b31c: display name [WebApplicationContext for namespace 'mycart-servlet']; startup date [Mon Nov 16 17:37:20 EST 2009]; root of context hierarchy [11/16/09 17:37:20:351 EST] 0000002d XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions Loading XML bean definitions from ServletContext resource [/WEB-INF/mycart-servlet.xml] [11/16/09 17:37:21:734 EST] 0000002d DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e72466: defining beans

By Khadeer Sharief on Nov 16, 2009 at 2:46 PM PST

[11/16/09 17:37:21:996 EST] 0000002d DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource [/WEB-INF/mycart-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.webflow.mvc.builder.MvcViewFactoryCreator] for bean with name 'viewFactoryCreator' defined in ServletContext resource [/WEB-INF/mycart-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.webflow.mvc.builder.MvcViewFactoryCreator at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method)

By khadeer sharief on Nov 16, 2009 at 2:48 PM PST

Hello,

I really like this tutorial and trying to get it working. I have the following error and I am at stage mycart2. I am using spring-framework-2.5.5. Which of the spring webflow works this spring -framework 2.5.5? I have tried

spring-webflow-2.0.0.RC1

then

spring-webflow-2.0.0.RELEASE

then

spring-webflow-2.0.7.RELEASE

[#|2009-11-17T01:04:53.571+0000|SEVERE|sun-appserver2.1|javax.enterprise.system.container.web| ThreadID=21;ThreadName=httpSSLWorkerThread-8080-1;_RequestID=e55d5273-6ace-4eeb-b9bc-f61dfe939219;|StandardWrapperValve[mycart]: PWC1406: Servlet.service() for servlet mycart threw exception java.lang.NoSuchMethodError: org.springframework.util.xml.DomUtils.getChildElementsByTagName(Lorg/w3c/dom/Element;[Ljava/lang/String;)Ljava/util/List; at org.springframework.webflow.engine.model.builder.xml.XmlFlowModelBuilder.parseStates(XmlFlowModelBuilder.java:312) at org.springframework.webflow.engine.model.builder.xml.XmlFlowModelBuilder.parseFlow(XmlFlowModelBuilder.java:242) at org.springframework.webflow.engine.model.builder.xml.XmlFlowModelBuilder.build(XmlFlowModelBuilder.java:128) at org.springframework.webflow.engine.model.registry.DefaultFlowModelHolder.assembleFlowModel(DefaultFlowModelHolder.java:88) at org.springframework.webflow.engine.model.registry.DefaultFlowModelHolder.getFlowModel(DefaultFlowModelHolder.java:62) at org.springframework.webflow.engine.builder.model.FlowModelFlowBuilder.doInit(FlowModelFlowBuilder.java:142) at org.springframework.webflow.engine.builder.support.AbstractFlowBuilder.init(AbstractFlowBuilder.java:54) at org.springframework.webflow.engine.builder.FlowAssembler.assembleFlow(FlowAssembler.java:90) at org.springframework.webflow.engine.builder.DefaultFlowHolder.assembleFlow(DefaultFlowHolder.java:96) at org.springframework.webflow.engine.builder.DefaultFlowHolder.getFlowDefinition(DefaultFlowHolder.java:77) at org.springframework.webflow.definition.registry.FlowDefinitionRegistryImpl.getFlowDefinition(FlowDefinitionRegistryImpl.java:60) at org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:131) at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:166) at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:157) at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

So which one of the webflow should I use?

Thanking you in advance.

eve

By evep on Nov 16, 2009 at 5:13 PM PST

i tried this mycart in tomcat 6.0.14 it didn't work .i placed following jar files in the lib/ any help is appreciated

11/16/2009 10:59 AM 60,841 commons-logging.jar 11/16/2009 12:32 PM 167,958 ognl-2.6.9.jar 08/08/2008 02:09 PM 142,366 org.springframework.binding-2.0.3.RELEASE.jar 08/08/2008 02:10 PM 1,019,277 org.springframework.js-2.0.3.RELEASE.jar 08/08/2008 02:11 PM 490,217 org.springframework.webflow-2.0.3.RELEASE.jar 11/16/2009 11:00 AM 404,466 spring-webmvc.jar 11/16/2009 10:59 AM 2,949,316 spring.jar

By khadeer sharief on Nov 16, 2009 at 7:27 PM PST

Hi,

I am running my application with glassfish v2.1 application server. It runs and load fine. But when I click on the register link on the mycart2, I get the above error pasted in evep message above.

Any ideas why?

thanking you.

eve

By evep on Nov 17, 2009 at 8:18 AM PST

Great!

Mine is working. Using glassfish v2.1, spring2.5.6 and spring webflow 2.0.3.

I have been searching all over for a servlet controller and cart example.

Thanks Wheeler.

eve

By evep on Nov 19, 2009 at 3:09 AM PST

This tutorial rocks!!!

Congratulations and thanks...

By DonPollo on Dec 4, 2009 at 4:36 PM PST

To get around "The requested resouce ... is not available" problem try using jboss-el.jar instead of ognl-2.6.9.jar - worked for me - download from link text

By ade on Dec 22, 2009 at 4:25 AM PST

can anyone help with this mycart3 problem please - I keep getting this exception when trying "http://localhost:8080/mycart3/home.do" -

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 99 in XML document from ServletContext resource [/WEB-INF/mycart-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:scoped-proxy'. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310) .........................

haven't changed the mycart-servlet.xml file so assume all the scehma locations are ok - any ideas? brilliant tutorial up to now but now a brick wall and would love to complete it!

added spring aop libs even though tutorial didn't say to but still no difference!

thanks in advance

ade

By ade on Dec 22, 2009 at 5:16 AM PST

Hi, It's very nice article....I struck up at this error.. Can you solve me this plz....

No adapter for handler [org.springframework.webflow.mvc.servlet.FlowController@1315415]: Does your handler implement a supported interface like Controller? at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1091) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) at javax.servlet.http.HttpServlet.service(HttpServlet.java:690) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)

By jayavardhan on Dec 29, 2009 at 6:05 AM PST

Hi,

everything works like a charm, but I can't understand why this statement

Cancel Checkout

in options.jsp forwards to the Checkout page insted of the home (every other "cancelCheckout" event goes to the home).

I'm using Tomcat 6.x

Thanks all, Ale

By Ale on Jan 4, 2010 at 8:30 AM PST

Sorry, I missed the statement:

button style="margin-left:5px" onclick="window.location='${flowExecutionUrl}&_eventId=cancelCheckout'">Cancel Checkout

By Ale on Jan 4, 2010 at 8:33 AM PST

I have that problem. do you know something about that?

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 60 in XML document from ServletContext resource [/WEB-INF/mycart-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'flow:flow-executor'.

By nikos on Jan 25, 2010 at 4:54 AM PST

"does your handler implement a supported ...."

the error message is caused by missing configuration register-servlet.xml

<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> 

up to the next error :(

By robert on Jan 29, 2010 at 4:27 AM PST

Very nice tutorial. :-)
As mentioned above, I only needed to tweak this: <%= request.getAttribute("flowExecutionUrl") %>

By my on Feb 8, 2010 at 6:26 AM PST

After some effort (because of exception getting thrown) made the application to work. I am using NetBeans. Included the following jars: org.springframework.js-2.0.4.jar org.springframework.binding-2.0.4.jar spring-2.5.5.jar springframework.webflow-2.0.8.jar spring-webmvc-2.5.5.jar asm-all-2.2.3 other than the mentioned ones

By Rajeev on Feb 10, 2010 at 3:58 AM PST

Well, I've got a fix, and also a problem. As a couple other folks were getting the same NullPointerException when hitting home.do in mycart3, I added the @Autowired annotation just above the setter for cartService in CartController, and that got rid of the exception. I thought that since we were using component scanning this wouldn't be required, but perhaps since the class is an @Controller rather than @Component, it would require an additional scan entry in the -servlet.xml file?

The problem on mycart3 I'm getting is the same as Gerald had back in 2008: Feb 14, 2010 2:35:01 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet mycart3 threw exception org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@63273 targetAction = [EvaluateAction@da5a9b expression = shoppingCart.addItem(cartService.getProduct(productId)), resultExposer = [null]], attributes = map[[empty]]] in state 'addToCart' of flow 'addToCart' -- action execution attributes were 'map[[empty]]'

Where it's failing on the evaluation line in the addToCart.xml file:

I basically copied the config files, and keep getting this issue. I didn't write my own EL. Kind of puzzling.

By Greg E on Feb 14, 2010 at 12:40 AM PST

Well, answered my own question. Adding the @Component annotation to the ShoppingCart bean fixed the particular exception I was getting.

By Greg E on Feb 14, 2010 at 5:00 PM PST

In my JSP, I have the following line to find what's there in ${flowExecutionUrl}

<%= request.getAttribute("flowExecutionUrl") %>

It prints null.

Excerpts:-

1.My JSP:-

<a href="${flowExecutionUrl}&_eventId=submitUNP"> </a> 

Note: I even tried <a href="${flowExecutionUrl}&_eventId_submitUNP"> </a>

2.My Flow:-

<transition on="submitUNP" to="doLogin" /> 

3.My web.xml:-

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.do</url-pattern>
        <el-ignored>false</el-ignored>
    </jsp-property-group>
</jsp-config> 

Please note that I am using Tomcat 5.5

What am I missing here?

Thanks in advance, Ajith Joseph

By Ajith Joseph on Feb 24, 2010 at 1:32 PM PST

I've found out a resolution for the above issue. It looks like EL is disabled by default [in tomcat5.X servlet container].

You can try any of the following resolutions:-

Solution 1: 1) Add <%@ page isELIgnored="false" %> to the JSP PS: Even though I had the following in my web.xml, it did not work [got to find out why so....]:- .jsp .do false

Solution 2: 2) Copy el-api.jar [from tomcat6 HOME\common\lib] to tomcat5.xHOME\common\lib PS: You may also copy el-api.jar to your application lib. That as well will work.

Solution 3: 3) Upgrade to Tomcat 6

My environment: Spring packages:- org.springframework.XXX-3.0.0.RELEASE.jar Web Flow package:- org.springframework.webflow-2.0.8.RELEASE.jar OGNL:- ognl-2.6.9.jar Web Container:- Tomcat 5.5

Cheers, Ajith Joseph

By Ajith Joseph on Mar 2, 2010 at 5:46 AM PST

HI,

I am just starting with Spring webflow and was following each of these steps. I am unable to load the http://localhost:8580/mycart2/home.do. I am using Spring webflow 2.0.6 as my existing application is in Spring 2.5 which we are not prepared to change now. Getting this exception. Please help Mar 22, 2010 5:50:11 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Allocate exception for servlet mycart org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'flow:flow-executor'. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown

By Manish Agrawal on Mar 22, 2010 at 3:16 PM PDT

That's really an awesome job and so helpful! Thanks a lot it's the best tutorial I could find on SWF2

By Guillaume Chaput on Apr 9, 2010 at 5:31 AM PDT

hi

i'm getting the following when i use the shoppingCart as a context root

HTTP Status 404 - /shoppingCart/account/$%7BflowExecutionUrl%7D&_eventId=cancelRegistration

type Status report

message /shoppingCart/account/$%7BflowExecutionUrl%7D&_eventId=cancelRegistration

description The requested resource (/shoppingCart/account/$%7BflowExecutionUrl%7D&_eventId=cancelRegistration) is not available. Apache Tomcat/6.0.18

By Farrukh Mahmud on Apr 14, 2010 at 5:54 AM PDT

got it working by following this

http://forum.springsource.org/showthread.php?t=64432

By Farrukh Mahmud on Apr 14, 2010 at 6:23 AM PDT

Hi all,

I just want to contribute to this nice tutorial. I found out that when using the: ognl-2.7.jar ognl-2.7.3.jar you get the error bellow. Be sure to use the ognl-2.6.9.jar when trying this tutorial.

The error generated when using another ognl verison: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0' defined in ServletContext resource [/WEB-INF/mycart-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowController' defined in ServletContext resource [/WEB-INF/mycart-servlet.xml]: Cannot resolve reference to bean 'flowExecutor' while setting bean property 'flowExecutor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowExecutor': Cannot resolve reference to bean 'flowRegistry' while setting bean property 'flowDefinitionLocator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowRegistry': Cannot resolve reference to bean 'flowBuilderServices' while setting bean property 'flowBuilderServices'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowBuilderServices': Cannot resolve reference to bean 'org.springframework.webflow.expression.DefaultExpressionParserFactory#0' while setting bean property 'expressionParser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.webflow.expression.DefaultExpressionParserFactory#0': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static synchronized org.springframework.binding.expression.ExpressionParser org.springframework.webflow.expression.DefaultExpressionParserFactory.getExpressionParser(org.springframework.binding.convert.ConversionService)] threw exception; nested exception is java.lang.IllegalStateException: Unable to create the default expression parser for Spring Web Flow: Neither a Unified EL implementation or OGNL could be found.

Regards, Deksa

By Deksa Jakim on Apr 22, 2010 at 4:44 AM PDT

sir I am using webflow 2.09 and spring 3 following error shows while running 2010-04-24 09:45:20,578 WARN [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/techconf/conferences.htm] in DispatcherServlet with name 'techconf' my web.xml

technology Conference

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/techconf-servlet.xml,/WEB-INF/applicationContext-security.xml,/WEB-INF/webflow-config.xml
    </param-value>
</context-param> 
 <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping> 

org.springframework.web.util.Log4jConfigListener org.springframework.web.context.ContextLoaderListener

techconf org.springframework.web.servlet.DispatcherServlet 1 techconf *.htm

<welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
</welcome-file-list> 

my servlets

<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /> 


when i remove the flow configuration it working

By arun on Apr 23, 2010 at 9:49 PM PDT

I am getting this error while building mycart2

java.lang.NoSuchMethodError: org.springframework.binding.convert.service.GenericConversionService.addConverter(Lorg/springframework/binding/convert/converters/Converter;)V

I have tried almost all JARS but none of helped.

By SANTOSH KUMAR on May 26, 2010 at 1:26 PM PDT

Dude, I'm new to Spring and I need to put up a demo site in 5 days.

I tried reading the docs, 2 books and several web pages on how to setup, and failed miserably.

Your article is the only human readable tutorial out there :)

Great job!

Best,

JOe

By Joe Jarin on Jun 2, 2010 at 4:40 AM PDT

Hi, first off - good work.

Now, I was looking to use this Web Flow 2 in my JSF shopping cart application. Can anyone point me to a good JSF - Web Flow 2 integration article? I can think of Flows controlling requests and maintaing view state, but I am not sure how to call a managed bean to say, validate date, and then return the control back to flow. I still have this working well with JSF using to solve 'refresh' problem, but I can think of some areas where too much coding is required to solve a small problem. I don't want to directly use HTTP Session anywhere and then kill it in some odd place. It just destroys the 'flow'.

Any help is appreciated.

Thanks.

By Tej on Jun 16, 2010 at 5:04 AM PDT

the error message is caused by missing configuration register-servlet.xml

I have the same problem (see below). Does that mean there is an additional config file with the above name missing? As it happens, the bean declaration for SimpleControllerHandlerAdapter appears in mycart-servlet.xml

14.07.2010 09:52:25 DEBUG DispatcherServlet: Testing handler adapter [org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter@135605a] (DispatcherServlet.java, line 976) 14.07.2010 09:52:25 DEBUG DispatcherServlet: Exception thrown in getLastModified (DispatcherServlet.java, line 864) javax.servlet.ServletException: No adapter for handler [org.springframework.webflow.mvc.servlet.FlowController@602b6b]: Does your handler implement a supported interface like Controller? at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:982) at org.springframework.web.servlet.DispatcherServlet.getLastModified(DispatcherServlet.java:854) at javax.servlet.http.HttpServlet.service(HttpServlet.java:686) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) 14.07.2010 09:52:25 DEBUG DispatcherServlet: Bound request context to thread: org.apache.catalina.connector.RequestFacade@688954 (FrameworkServlet.java, line 643)

By charlie on Jul 14, 2010 at 6:41 AM PDT

The Pandora pandora schmuck myth first Pandora Armreifenappears in lines Pandora Halsketten of Hesiod's poem in Pandora Charms epic meter, the Theogony (ca. 8th?7th centuries BC), without ever giving the woman a name. After humans Pandora Sets have received thethe myth is a rosetta stone kind of theodicy, addressing the question pop information, web easy get, sports fashion, news-fashionof why there is evil in the world. In the seventh hot-winter century BC, Hesiod, both in his Theogony (briefly, without naming Pandora outright rosetta stone language, rosetta stone spanish, abercrombie and fitch , Abercrombie Fitch

By pandora schmuck on Aug 30, 2010 at 11:16 PM PDT

Post a comment

Your name:
Your e-mail address (won't be displayed):
Your web site (optional):
example: www.xyz.com
Your comment:
Preview:
By You
Please help us reduce comment spam:
Spring in Practice
My brother and I are writing Spring in Practice for Manning!

What's New?

2009-08-30 - Check out my two-part series on DZone: Spring Integration: A Hands-On Tutorial.
2009-03-25 - My new article Getting Started with Spring Batch 2.0 is available on DZone.
Home | Consulting | Tech Articles | Mailing List | Contact | Spring Blog
Copyright © 2008 Wheeler Software, LLC.