From b4eeec51826a0fa94190f7f3e9cdaf973c4787eb Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Fri, 20 Mar 2009 04:19:49 +0000 Subject: [PATCH] step 2.0 --- .../main/webapp/WEB-INF/spring/mvc-config.xml | 2 +- .../webapp/WEB-INF/tutorial/webflowSetup.jsp | 91 ++++++++++++++++++- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/spring/mvc-config.xml b/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/spring/mvc-config.xml index c9d3ed20..9585a223 100644 --- a/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/spring/mvc-config.xml +++ b/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/spring/mvc-config.xml @@ -34,7 +34,7 @@ - + diff --git a/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowSetup.jsp b/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowSetup.jsp index 11a7c7bf..7949929a 100644 --- a/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowSetup.jsp +++ b/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowSetup.jsp @@ -1,6 +1,6 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page session="false" %> - + Getting Started with Spring Web Flow: Setting up Web Flow in a Spring Web Application @@ -12,17 +12,100 @@ What does the configuration of a typical Spring web application look like?

+ The configuration of every Spring web application starts in web.xml. + There, a Spring MVC DispatcherServlet is defined to process all requests into the application. + The DispatcherServlet itself is configured using a Spring container. + It is responsible for routing web requests to the proper application controllers, such as your Spring MVC @Controllers and web flows. + A typical DispatcherServlet declaration is shown below: +

+
+	<!-- The front controller of this Spring MVC application, responsible for handling all application requests -->
+	<servlet>
+		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
+		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+		<init-param>
+			<param-name>contextConfigLocation</param-name>
+			<param-value>
+				/WEB-INF/spring/*.xml
+			</param-value>
+		</init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+		
+	<!-- Map all /app requests to the DispatcherServlet for handling -->
+	<servlet-mapping>
+		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
+		<url-pattern>/app/*</url-pattern>
+	</servlet-mapping>
+
+

+ This DispatcherServlet is configured to process requests into /app/*. + The servlet's configuration is defined in the .xml files in /WEB-INF/spring. +

+

+ How are Spring configuration files typically organized? +

+

+ Inside /WEB-INF/spring, we generally recommend defining a configuration file for your application logic, + and separate configuration files for framework infrastructure. For example: +

+
+	/webapp
+		/WEB-INF
+			/spring
+				app-config.xml
+				mvc-config.xml
+				webflow-config.xml		
+
+

+ The example above shows the configuration for a Spring web application spread across three files. + app-config.xml configures your components that carry out application-specific controller, business, and data access logic. + mvc-config.xml configures the Spring MVC framework infrastructure, including the properties of the DispatcherServlet. + webflow-config configures the Spring Web Flow infrastructure, which plugs into Spring MVC.

How do I plug-in Spring Web Flow?

+ In webflow-config.xml, first define a flow-registry to register the flows you have defined in your application:

-

- How do I create and deploy new flows? -

+
+	<!-- Registers the web flows that can be executed -->	
+	<webflow:flow-registry id="flowRegistry" base-path="/WEB-INF/">
+		<webflow:flow-location-pattern value="**/*-flow.xml" />
+	</webflow:flow-registry>
+

+ The example above scans /WEB-INF looking for -flow.xml files and registers them.

+

+ Then, define a flow-executor that uses this registry to execute your flows: +

+
+	<!-- Configures the engine that executes web flows in this application -->
+	<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry" />
+
+

+ Finally, in mvc-config.xml plug in adapters to hook the flow-executor into the Spring MVC DispatcherServlet request processing pipeline: +

+
+	<!-- Maps requests to flows in the flowRegistry -->
+	<bean id="flowMappings" class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
+		<property name="order" value="0" />
+		<property name="flowRegistry" ref="flowRegistry" />
+	</bean>
+
+	<!-- Enables Spring Web Flow as a Spring MVC request handler -->
+	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
+		<property name="flowExecutor" ref="flowExecutor" />
+	</bean>
+
+

+ We also recommend you turn on development mode while developing so you never have to redeploy your application to test changes: +

+
+	<webflow:flow-builder-services id="flowBuilderServices" development="true" />
+

Next >