Sunday 31 July 2011

Spring WebFlow- Hello WebFlow

Spring WebFlow is an extension point to spring MVC. In a typical spring mvc model, all requests are processed via controllers. In Spring Webflow, requests are processed through flow executor. Spring Web Flow (SWF) is a component of the Spring Framework's web stack focused on the definition and execution of UI flow within a web application. Spring Web Flow, like Spring, is a layered framework, packaged in a manner that allows teams to use the parts they need and nothing else. For example, one team might use Spring Web Flow in a Servlet environment with Spring MVC and thus require the Spring MVC integration. Another team might use SWF in a Portlet environment, and thus require the Portlet MVC integration. Another team might mix and match. A major benefit of SWF is that it allows you to define reusable, self-contained controller modules that can execute in any environment. Spring Web Flow allows developers to build reusable, self-contained controller modules called flows. A flow defines a user dialog that responds to user events to drive the execution of application code to complete a business goal.

For creating this example,i refereed Spring Web flow tutorial.


In Web.xml,
    <display-name>
    HelloWebFlow</display-name>
    <servlet>
        <servlet-name>HelloWebFlow</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <!-- Map all spring requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>HelloWebFlow</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  

In HelloWebFlow-Servlet.xml
    <mvc:default-servlet-handler/>

<!-- Map paths directly to view names without controller processing. Use the view-name attribute if necessary: by convention the view name equals the path without the leading slash -->
   <mvc:view-controller path="/" view-name="index" />
   
<!-- Maps request paths to flows in the flowRegistry; e.g. a path of /hello looks for a flow with id "hello". -->
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="order" value="-1"/>
        <property name="flowRegistry" ref="flowRegistry" />
    </bean>
   
<!-- Dispatches requests mapped to flows to FlowHandler implementations -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
</bean>

   
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
    <webflow:flow-executor  id="flowExecutor"/>
    <!-- The registry of executable flow definitions -->
    <webflow:flow-registry id="flowRegistry">
        <webflow:flow-location path="/WEB-INF/flows/hello.xml" />
    </webflow:flow-registry>    




No comments:

Post a Comment