diff --git a/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowExercise.jsp b/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowExercise.jsp index 835b3545..2ae63f42 100644 --- a/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowExercise.jsp +++ b/spring-webflow-samples/getting-started-with-spring-webflow/src/main/webapp/WEB-INF/tutorial/webflowExercise.jsp @@ -68,14 +68,12 @@
  • Go ahead and create a start.jsp in your flow directory and paste in the following:
    -		<html>
    -			<head>
    -				<title>Hello world!</title>
    -			</head>
    -			<h1>
    -				Hello world!
    -			</h1>
    -		</html>
    +    <html>
    +        <head>
    +            <title>Hello world!</title>
    +        </head>
    +        <h1>Hello world!</h1>
    +    </html>
     			
  • @@ -91,29 +89,27 @@
  • Next, try transitioning your flow from one state to another to implement a navigation rule. In your helloworld flow, add the following transition to your start view-state:
    -		<transition on="submit" to="page2" />
    +    <transition on="submit" to="page2" />
     			
    Then define your page2 view-state:
    -		<view-state id="page2">
    -		</view-state>
    +    <view-state id="page2">
    +    </view-state>
     			
    And the corresponding page2.jsp:
    -		<html>
    -			<head>
    -				<title>Hello world!</title>
    -			</head>
    -			<h1>
    -				This is page 2!
    -			</h1>
    -		</html>
    +    <html>
    +        <head>
    +            <title>Hello world!</title>
    +        </head>
    +        <h1>This is page 2!</h1>
    +    </html>
     			
    Finally, create a button on your start.jsp that raises the submit event to trigger the state transition:
    -		<form method="post">
    -			<input type="submit" name="_eventId_submit" value="Submit" />
    -		</form>
    +    <form method="post">
    +        <input type="submit" name="_eventId_submit" value="Submit" />
    +    </form>
     			
    Click the button and you should be taken to page 2.
  • @@ -129,49 +125,47 @@ Try implementing a dynamic navigation rule by first adding a bound checkbox to your start.jsp. Do this by replacing its contents with the following snippet:
    -		<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    -		<html>
    -			<head>
    -				<title>Hello world!</title>
    -			</head>
    -			<h1>
    -				Hello world!
    -			</h1>
    -			<form:form method="post" modelAttribute="helloWorldForm">
    -				<form:checkbox path="selected" />
    -				<input type="submit" name="_eventId_submit" value="Submit" />
    -			</form:form>		
    -		</html>
    +    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    +    <html>
    +        <head>
    +            <title>Hello world!</title>
    +        </head>
    +        <h1>Hello world!</h1>
    +        <form:form method="post" modelAttribute="helloWorldForm">
    +            <form:checkbox path="selected" />
    +            <input type="submit" name="_eventId_submit" value="Submit" />
    +        </form:form>		
    +    </html>
     			
  • Next, create a HelloWorldForm class in the org.springframework.webflow.samples.helloworld package with the following code:
    -		package org.springframework.webflow.samples.helloworld;
    +    package org.springframework.webflow.samples.helloworld;
     		
    -		import java.io.Serializable;
    +    import java.io.Serializable;
     		
    -		public class HelloWorldForm implements Serializable {
    -		    private boolean selected = true;
    -		    
    -		    public boolean isSelected() {
    -		        return selected;
    -		    }
    -		    
    -		    public void setSelected(boolean selected) {
    -		        this.selected = selected;
    -		    }
    -		}
    +    public class HelloWorldForm implements Serializable {
    +        private boolean selected = true;
    +        
    +        public boolean isSelected() {
    +            return selected;
    +        }
    +        
    +        public void setSelected(boolean selected) {
    +            this.selected = selected;
    +        }
    +    }
     			
  • At the top of your helloworld-flow, declare the HelloWorldForm as a flow variable:
    -		<var name="helloWorldForm" class="org.springframework.webflow.samples.helloworld.HelloWorldForm" />
    +    <var name="helloWorldForm" class="org.springframework.webflow.samples.helloworld.HelloWorldForm" />
     			
    Then update your start view-state to use this variable as its data model, enabling automatic model binding and validation:
    -		<view-state id="start" model="helloWorldForm"> ...	
    +    <view-state id="start" model="helloWorldForm"> ...	
     			

    Refresh your flow and the checkbox should render checked since the default value for the HelloWorldForm selected property is true. @@ -181,21 +175,21 @@

  • Now insert a decision state that says if the checkbox is selected goto page2, else goto a new page3:
    	
    -		<decision-state id="isSelected">
    -			<if test="helloWorldForm.selected" then="page2" else="page3" />
    -		</decision-state>
    +    <decision-state id="isSelected">
    +        <if test="helloWorldForm.selected" then="page2" else="page3" />
    +    </decision-state>
     	
    -		<view-state id="page2">
    -		</view-state>	
    +    <view-state id="page2">
    +    </view-state>	
     	    
    -		<view-state id="page3">
    -		</view-state>	
    +    <view-state id="page3">
    +    </view-state>	
     			
    Be sure to update your start view-state to transition to the isSelected decision state instead of page2 directly:
    -		<view-state id="start">
    -			<transition on="submit" to="isSelected" />
    -		</view-state>		
    +    <view-state id="start">
    +        <transition on="submit" to="isSelected" />
    +    </view-state>		
     			
    Click the Submit button with the checkbox selected and you should be taken to page2. Click the button with the checkbox de-selected and you should be taken to page3 (you'll need to create a JSP or you'll get a 404). @@ -208,15 +202,15 @@
  • Finish up your helloworld flow by adding another button on the start.jsp that ends the flow:
    -		<input type="submit" name="_eventId_finish" value="Finish" />
    +    <input type="submit" name="_eventId_finish" value="Finish" />
     			
    In your start view-state, declare the finish transition:
    -		<transition on="finish" to="finished" />
    +    <transition on="finish" to="finished" />
     			
    And finally define the end-state:
    -		<end-state id="finished" view="externalRedirect:welcome" />
    +    <end-state id="finished" view="externalRedirect:welcome" />
     			
    Click the Finish button and you should be taken back to the application welcome screen.
  • 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 6b3b4bef..6218e976 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 @@ -29,24 +29,24 @@ If you prefer to go right to implementing your first flow, you can - <!-- 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> + <!-- 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/*. @@ -62,13 +62,13 @@ If you prefer to go right to implementing your first flow, you can - /webapp - /WEB-INF - /spring - app-config.xml - mvc-config.xml - webflow-config.xml - web.xml + /webapp + /WEB-INF + /spring + app-config.xml + mvc-config.xml + webflow-config.xml + web.xml

    The example above shows the configuration for a Spring web application spread across three files. @@ -81,8 +81,8 @@ If you prefer to go right to implementing your first flow, you can - <!-- Scans within the base package of the application for @Components to configure as beans --> - <context:component-scan base-package="org.springframework.webflow.samples.gettingstarted" /> + <!-- Scans within the base package of the application for @Components to configure as beans --> + <context:component-scan base-package="org.springframework.webflow.samples.gettingstarted" />

    With this technique, your Spring configuration is setup once and you generally never have to update your configuration files again as new components are added to your application. @@ -96,10 +96,10 @@ If you prefer to go right to implementing your first flow, you can - <!-- 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> + <!-- 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. @@ -108,29 +108,29 @@ If you prefer to go right to implementing your first flow, you can - <!-- Configures the engine that executes web flows in this application --> - <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry" /> + <!-- 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>
    +    <!-- 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" />
    +    <webflow:flow-builder-services id="flowBuilderServices" development="true" />
     	
    @@ -150,18 +150,18 @@ If you prefer to go right to implementing your first flow, you can - <!-- Maps requests to flows in the flowRegistry; for example, a request for resource /hotels/booking maps to a flow with id "hotels/booking" - If no flow is found with that id, Spring MVC proceeds to the next HandlerMapping (order=1 below). --> - <bean id="flowMappings" class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> - <property name="order" value="0" /> - <property name="flowRegistry" ref="flowRegistry" /> - </bean> - - <!-- Maps requests to @Controllers based on @RequestMapping("path") annotation values - If no annotation-based path mapping is found, Spring MVC proceeds to the next HandlerMapping (order=2 below). --> - <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> - <property name="order" value="1" /> - </bean> + <!-- Maps requests to flows in the flowRegistry; for example, a request for resource /hotels/booking maps to a flow with id "hotels/booking" + If no flow is found with that id, Spring MVC proceeds to the next HandlerMapping (order=1 below). --> + <bean id="flowMappings" class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> + <property name="order" value="0" /> + <property name="flowRegistry" ref="flowRegistry" /> + </bean> + + <!-- Maps requests to @Controllers based on @RequestMapping("path") annotation values + If no annotation-based path mapping is found, Spring MVC proceeds to the next HandlerMapping (order=2 below). --> + <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> + <property name="order" value="1" /> + </bean>

    Once a request has been mapped to a handler object such as a @Controller of web flow, the DispatcherServlet uses the HandlerAdapter registered for that kind of handler to invoke it. @@ -169,13 +169,13 @@ If you prefer to go right to implementing your first flow, you can - <!-- Enables annotated @Controllers; responsible for invoking an annotated POJO @Controller when one is mapped. --> - <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> - - <!-- Enables web flows; responsible for calling the Spring Web Flow system to execute a flow when one is mapped. --> - <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> - <property name="flowExecutor" ref="flowExecutor" /> - </bean> + <!-- Enables annotated @Controllers; responsible for invoking an annotated POJO @Controller when one is mapped. --> + <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> + + <!-- Enables web flows; responsible for calling the Spring Web Flow system to execute a flow when one is mapped. --> + <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> + <property name="flowExecutor" ref="flowExecutor" /> + </bean>

    To illustrate a typical DispatcherServlet pipeline, the following graphic illustrates the sequence of events that happen in this application when the /tutorial resource is requested, which is handled by the web flow you are interacting with right now: