org.springframework.webflow.executor.struts
Class FlowAction

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by org.springframework.web.struts.ActionSupport
          extended by org.springframework.webflow.executor.struts.FlowAction

public class FlowAction
extends org.springframework.web.struts.ActionSupport

Point of integration between Struts and Spring Web Flow: a Struts Action that acts a front controller entry point into the web flow system. A single FlowAction may launch any new FlowExecution. In addition, a single Flow Action may signal events in any existing/restored FlowExecutions.

Requests are managed by and delegated to a FlowExecutor, which this class delegates to using a FlowRequestHandler (allowing reuse of common front flow controller logic in other environments). Consult the JavaDoc of those classes for more information on how requests are processed.

  • By default, to have this controller launch a new flow execution (conversation), have the client send a FlowExecutorArgumentHandler.getFlowIdArgumentName() request parameter indicating the flow definition to launch.
  • To have this controller participate in an existing flow execution (conversation), have the client send a FlowExecutorArgumentHandler.getFlowExecutionKeyArgumentName() request parameter identifying the conversation to participate in.

    On each request received by this action, a StrutsExternalContext object is created as input to the web flow system. This external source event provides access to the action form, action mapping, and other Struts-specific constructs.

    This class also is aware of the SpringBindingActionForm adapter, which adapts Spring's data binding infrastructure (based on POJO binding, a standard Errors interface, and property editor type conversion) to the Struts action form model. This option gives backend web-tier developers full support for POJO-based binding with minimal hassel, while still providing consistency to view developers who already have a lot of experience with Struts for markup and request dispatching.

    Below is an example struts-config.xml configuration for a FlowAction:

         <action path="/userRegistration"
             type="org.springframework.webflow.executor.struts.FlowAction"
             name="springBindingActionForm" scope="request">
         </action>
     
    This example maps the logical request URL /userRegistration.do as a Flow controller (FlowAction). It is expected that flows to launch be provided in a dynamic fashion by the views (allowing this single FlowAction to manage any number of flow executions). A Spring binding action form instance is set in request scope, acting as an adapter enabling POJO-based binding and validation with Spring.

    Other notes regarding Struts/Spring Web Flow integration:

    The benefits here are considerable: developers now have a powerful web flow capability integrated with Struts, with a consistent-approach to POJO-based binding and validation that addresses the proliferation of ActionForm classes found in traditional Struts-based apps.

    Author:
    Keith Donald, Erwin Vervaet
    See Also:
    FlowExecutor, FlowRequestHandler, SpringBindingActionForm, DelegatingActionProxy

    Field Summary
    protected static java.lang.String FLOW_EXECUTOR_ARGUMENT_HANDLER_BEAN_NAME
              The flow executor argument handler will be retreived from the application context using this bean name if no argument handler is explicitly set.
    protected static java.lang.String FLOW_EXECUTOR_BEAN_NAME
              The flow executor will be retreived from the application context using this bean name if no executor is explicitly set.
     
    Fields inherited from class org.apache.struts.action.Action
    defaultLocale, servlet
     
    Constructor Summary
    FlowAction()
               
     
    Method Summary
    protected  org.apache.struts.action.ActionForward createRedirectForward(java.lang.String url, javax.servlet.http.HttpServletResponse response)
              Handles a redirect.
    protected  FlowRequestHandler createRequestHandler()
              Factory method that creates a new helper for processing a request into this flow controller.
     org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
               
    protected  org.apache.struts.action.ActionForward findForward(ApplicationView forward, org.apache.struts.action.ActionMapping mapping)
              Find an action forward for given application view.
     FlowExecutorArgumentHandler getArgumentHandler()
              Returns the flow executor argument handler used by this controller.
     FlowExecutor getFlowExecutor()
              Returns the flow executor used by this controller.
    protected  void onInit()
               
     void setArgumentHandler(FlowExecutorArgumentHandler argumentHandler)
              Sets the flow executor argument handler to use.
     void setFlowExecutor(FlowExecutor flowExecutor)
              Configures the flow executor implementation to use.
    protected  org.apache.struts.action.ActionForward toActionForward(ResponseInstruction responseInstruction, org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ExternalContext context)
              Return a Struts ActionForward given a ResponseInstruction.
     
    Methods inherited from class org.springframework.web.struts.ActionSupport
    getMessageSourceAccessor, getServletContext, getTempDir, getWebApplicationContext, initWebApplicationContext, onDestroy, setServlet
     
    Methods inherited from class org.apache.struts.action.Action
    addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    FLOW_EXECUTOR_BEAN_NAME

    protected static final java.lang.String FLOW_EXECUTOR_BEAN_NAME
    The flow executor will be retreived from the application context using this bean name if no executor is explicitly set. ("flowExecutor")

    See Also:
    Constant Field Values

    FLOW_EXECUTOR_ARGUMENT_HANDLER_BEAN_NAME

    protected static final java.lang.String FLOW_EXECUTOR_ARGUMENT_HANDLER_BEAN_NAME
    The flow executor argument handler will be retreived from the application context using this bean name if no argument handler is explicitly set. ("argumentHandler")

    See Also:
    Constant Field Values
    Constructor Detail

    FlowAction

    public FlowAction()
    Method Detail

    getFlowExecutor

    public FlowExecutor getFlowExecutor()
    Returns the flow executor used by this controller.

    Returns:
    the flow executor

    setFlowExecutor

    public void setFlowExecutor(FlowExecutor flowExecutor)
    Configures the flow executor implementation to use. Required.

    Parameters:
    flowExecutor - the fully configured flow executor

    getArgumentHandler

    public FlowExecutorArgumentHandler getArgumentHandler()
    Returns the flow executor argument handler used by this controller.

    Returns:
    the argument handler

    setArgumentHandler

    public void setArgumentHandler(FlowExecutorArgumentHandler argumentHandler)
    Sets the flow executor argument handler to use.

    Parameters:
    argumentHandler - the fully configured argument handler

    onInit

    protected void onInit()
    Overrides:
    onInit in class org.springframework.web.struts.ActionSupport

    execute

    public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
                                                          org.apache.struts.action.ActionForm form,
                                                          javax.servlet.http.HttpServletRequest request,
                                                          javax.servlet.http.HttpServletResponse response)
                                                   throws java.lang.Exception
    Overrides:
    execute in class org.apache.struts.action.Action
    Throws:
    java.lang.Exception

    createRequestHandler

    protected FlowRequestHandler createRequestHandler()
    Factory method that creates a new helper for processing a request into this flow controller.

    Returns:
    the controller helper

    toActionForward

    protected org.apache.struts.action.ActionForward toActionForward(ResponseInstruction responseInstruction,
                                                                     org.apache.struts.action.ActionMapping mapping,
                                                                     org.apache.struts.action.ActionForm form,
                                                                     javax.servlet.http.HttpServletRequest request,
                                                                     javax.servlet.http.HttpServletResponse response,
                                                                     ExternalContext context)
                                                              throws java.lang.Exception
    Return a Struts ActionForward given a ResponseInstruction. Adds all attributes from the ResponseInstruction as request attributes.

    Throws:
    java.lang.Exception

    createRedirectForward

    protected org.apache.struts.action.ActionForward createRedirectForward(java.lang.String url,
                                                                           javax.servlet.http.HttpServletResponse response)
                                                                    throws java.lang.Exception
    Handles a redirect. This implementation simply calls sendRedirect on the response object.

    Parameters:
    url - the url to redirect to
    response - the http response
    Returns:
    the redirect forward, this implementation returns null
    Throws:
    java.lang.Exception - an excpetion occured processing the redirect
    See Also:
    HttpServletResponse.sendRedirect(java.lang.String)

    findForward

    protected org.apache.struts.action.ActionForward findForward(ApplicationView forward,
                                                                 org.apache.struts.action.ActionMapping mapping)
    Find an action forward for given application view. If no suitable forward is found in the action mapping using the view name as a key, this method will create a new action forward using the view name.

    Parameters:
    forward - the application view to find a forward for
    mapping - the action mapping to use
    Returns:
    the action forward, never null


    Copyright © 2004-2007. All Rights Reserved.