Now that we've gotten Spring MVC and SWF working, it's time to build out the shopping cart application. Please download the following file before continuing:
We won't be looking at every aspect of this application, but I'll highlight the most interesting pieces from a SWF point of view.
Besides the dependencies we had for mycart2.zip, there are four others you'll need:
cglib-nodep-2.1_3.jarjstl.jarstandard.jarsitemesh-2.3.jar (from www.opensymphony.com/sitemesh/download.action)After you download mycart3.zip (and its dependencies), you can
deploy it and then point your browser at
http://localhost:8080/mycart/home.do
Here are some notes to keep in mind:
/WEB-INF/jsp/pagetemplate.jsp in this case) according to
a simple configuration file (/WEB-INF/decorators.xml).
If however you don't want to use Sitemesh, simply remove the filter
from web.xml and Sitemesh is gone.Any given app may contain multiple flows, and mycart3
is such an app. We have four different flows:
addToCart: add an item to a shopping cartcheckout: shopping cart checkout processlogin: log into the appregister: register for a new user accountIn some of the cases we have what we would intuitively consider a flow in that there are multiple states involved; in other cases there is only one state to speak of and so it may seem strange to regard the flow as being a flow. However we'll see how that can make sense in the following section.
To create multiple flows, you will need to do the following.
First, create the flow definition files and put them in your
/WEB-INF/flows directory (or wherever you decided to put
them). Then add the flow locations to the flow registry, and the flow
URL mappings to your SimpleUrlHandlerMapping (if that's
what you're using), in your Spring application context, like so:
/WEB-INF/mycart-servlet.xml
...
<bean id="flowUrlMappings" class=
"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/addToCart.do=flowController
/checkout.do=flowController
/account/login.do=flowController
/account/register.do=flowController
</value>
</property>
<property name="alwaysUseFullPath" value="true"/>
</bean>
<flow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<flow:flow-location path="/WEB-INF/flows/addToCart.xml"/>
<flow:flow-location path="/WEB-INF/flows/checkout.xml"/>
<flow:flow-location path="/WEB-INF/flows/login.xml"/>
<flow:flow-location path="/WEB-INF/flows/register.xml"/>
</flow:flow-registry>
...
Once you have those in place you should be set up for multiple flows. Point your links at them and try them out!