In this post we will see the major concepts relates to Spring web flow. Spring flow is an approach to implement multi page flow web applications like shopping portal.\u00a0 For example in shopping portal application a user may involve in the below steps.<\/p>\n
As there are multiple pages involved in the shopping flow, the data needs to be carried throughout multiple pages. If we handle this task manually it will be tedious task. We will go out of our indented business logic. To implement these kinds of tasks easily Spring provides the web flow framework.<\/p>\n
A flow is nothing but a set of tasks to be done in a particular order. In webflow it is an xml file which tells the exactly how this flow should works. If we configure our application flow in spring web flow, the data carrying portion as well as the page navigation issues will be taken care by spring web flow itself. We can concentrate on our business logic rather than spending time on working those mundane tasks.<\/p>\n
Spring web flow can be configured only via xml file. Currently it is not feasible to configure via only java.<\/p>\n
The first thing to setup a web flow is configuration. A flow configuration involves below major components. Let’s go through them.<\/p>\n
Flow executor:\u00a0<\/strong>Flow executor is responsible to drive the flow.\u00a0 The syntax will be like below.<\/p>\n Flow Registry:\u00a0<\/strong>Flow registry is responsible to load the flow definitions. For example if all flows under folder\u00a0WEB-INF\/flows<\/span>\u00a0needs to be loaded it has to be configured like\u00a0 below.<\/p>\n Here one important thing to note is the url path to the flow will be determined by the path of the flow location.\u00a0 For example if the path of a flow is\u00a0\/WEB-INF\/flows\/order\/order-flow.xml<\/span>\u00a0 then the id will be order<\/span>\u00a0 (relative to the base path.) So the flow will be triggered while accessing the url http:\/\/{url}\/{contextpath}\/order<\/span><\/p>\n Instead of the pattern the path of the flow file also can be configured. For example to load\u00a0order-flow.xml<\/span>\u00a0flow it can be configured like below.<\/p>\n If the full path is specified then the filename will become the id of that flow. In the above case it will be order-flow<\/span>\u00a0. If id needs to be different from the path it can be specified with id attribute like below.<\/p>\n As per the above code the flow will be triggered when the url {contextPath}\/custom\/path\/<\/span>\u00a0flow is entered.<\/p>\n Flow Handler Mapping :\u00a0<\/strong>Like DispatcherServlet<\/span>\u00a0 for controller mapping, there is a class FlowHandlerMapping<\/span>\u00a0 for URL to flow mapping for web flow.<\/p>\n Flow Handler Adapter :\u00a0<\/strong>Like Controllers for handling the requests, there is a class FlowHandlerAdapter<\/span>\u00a0 to handle the flow requests<\/p>\n The next important thing is the flow.\u00a0\u00a0A Flow is an xml file which tells the exactly how this flow should works. A flow will have three major components.<\/p>\n State :\u00a0<\/strong>As per the name it is the state of the flow, which means the flows should be in a state.\u00a0 There are five types of states possible.<\/p>\n Transition:\u00a0<\/strong>To move from one state to another state the transition element will be used.<\/p>\n Data: <\/strong>To store and pass data through out the flow the data elements will be used. The syntax will be <var name=”customer” class=”org.span.domain.Customer”\/><\/span><\/p>\n That is all about the major components of the web flow. Also web flow can be secured as well. To secure a flow it has to be configured like below.<\/p>\n attributes<\/span>\u00a0 are comma separated roles. match<\/span>\u00a0\u00a0can be ‘any’ – At least one role required<\/span>\u00a0 or ‘all’ – All roles required<\/span>\u00a0.<\/p>\n In this section we have discussed the concepts of Spring web flow. In the next tutorial we will implement a simple web flow application to understand all the discussed concepts.<\/p>\n","protected":false},"excerpt":{"rendered":" In this post we will see the major concepts relates to Spring web flow. Spring flow is an approach to implement multi page flow web applications like shopping portal.\u00a0 For example in shopping portal application a user may involve in … Continue reading <flow:flow-executor id=\"flowExecutor\"\/><\/pre>\n
<flow:flow-registry id=\"flowRegistry\" base-path=\"\/WEB-INF\/flows\">\n<flow:flow-location-pattern value = \"**\/*-flow.xml\"\/> \n<\/flow:flow-registry><\/pre>\n
<flow:flow-registry id=\"flowRegistry\"> <flow:flow-location path = \"\/WEB-INF\/flows\/order\/order-flow.xml\"\/> <\/flow:flow-registry><\/pre>\n
<flow:flow-location path = \"\/WEB-INF\/flows\/order\/order-flow.xml\" id=\"custom\/path\/flow\"\/><\/pre>\n
\n
\n
\n
<\/li>\n<\/ul>\n<\/li>\n\n
<action-state id=\"saveOrder\">\n <evaluate expression=\"pizzaFlowActions.saveOrder(order)\"\/>\n <transition to=\"thankYou\"\/>\n<\/action-state><\/pre>\n<\/li>\n
\n
<decision-state id=\"checkDeliveryArea\">\n <if test=\"pizzaFlowActions.checkDeliveryArea(customer.zipCode)\" \n then=\"addCustomer\" else=\"deliveryWarning\"\/>\n<\/decision-state><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n
\n
<subflow-state id=\"order\" subflow=\"pizza\/order\">\n <input name=\"order\" value=\"order\"\/>\n <transition on=\"orderCreated\" to=\"payment\"\/>\n<\/subflow-state><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n
\n
\n
<global-transitions>\n <transition on=\"cancel\" to=\"endState\"\/>\n<\/global-transitions><\/pre>\n<\/li>\n<\/ul>\n
\n
\n
<view-state id=\"restricted\" view=\"paymentdetails\">\n <secured attributes=\"ROLE_ADMIN,ROLE_FINANCE\" match=\"all\"\/>\n<\/view-state><\/pre>\n