Announcement Announcement Module
Collapse
No announcement yet.
Is it possible to obtain the webflow's viewScope data from the MultiActionController? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to obtain the webflow's viewScope data from the MultiActionController?

    I created a Utility class to retrieve the formObject from Weblfow's viewScope (repository) using Spring MVC 2.5.2 & SWF 1.0.5

    here's the link:
    able to retrieve the formObject via flowExecution

    Now, upgraded to Spring MVC 2.5.6.SEC02 & SWF 2.0.9.RELEASE

    here's the revised code:
    Code:
    import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.webflow.context.ExternalContext;
    import org.springframework.webflow.context.ExternalContextHolder;
    import org.springframework.webflow.context.servlet.ServletExternalContext;
    import org.springframework.webflow.execution.FlowExecution;
    import org.springframework.webflow.execution.FlowExecutionKey;
    import org.springframework.webflow.execution.repository.FlowExecutionRepository;
    import org.springframework.webflow.executor.FlowExecutorImpl;
    import org.springframework.webflow.mvc.servlet.FlowController;
    import org.springframework.webflow.executor.support.FlowExecutorArgumentHandler;
    
    /**
     * WebFlow Utility
     */
    public final class WebFlowUtils {
    
        /**
         * Constructor
         */
        private WebFlowUtils() {
        }
    
        /**
         * Retrieve FormObject from Managed Webflow (Repository)
         * @param request
         * @param response
         * @param applicationContext
         * @param servletContext
         * @param formObjectName
         * @return FormObject
         */
        public static Object getFormObject(HttpServletRequest request, HttpServletResponse response,
                ApplicationContext applicationContext, ServletContext servletContext,
                String formObjectName) {
    
            FlowController controller = getFlowController(applicationContext);
    
            FlowExecutorArgumentHandler handler = controller.getArgumentHandler();
    
            ExternalContext externalContext = new ServletExternalContext(servletContext, request,
                    response);
    
            Object object = null;
    
            if (handler.isFlowExecutionKeyPresent(externalContext)) {
                try {
    
                    ExternalContextHolder.setExternalContext(externalContext);
    
                    FlowExecution flowExecution = getFlowExecution(controller, handler, externalContext);
    
                    object = flowExecution.getActiveSession().getScope().get(formObjectName);
                } finally {
                    ExternalContextHolder.setExternalContext(null);
                }
            }
            return object;
        }
    
        /**
         * Set FormObject back to Managed Webflow (Repository)
         * @param request
         * @param response
         * @param applicationContext
         * @param servletContext
         * @param formObjectName
         * @param formObject
         */
        public static void setFormObject(HttpServletRequest request, HttpServletResponse response,
                ApplicationContext applicationContext, ServletContext servletContext,
                String formObjectName, Object formObject) {
    
            FlowController controller = getFlowController(applicationContext);
    
            FlowExecutorArgumentHandler handler = controller.getArgumentHandler();
    
            ExternalContext externalContext = new ServletExternalContext(servletContext, request,
                    response);
    
            if (handler.isFlowExecutionKeyPresent(externalContext)) {
                try {
    
                    ExternalContextHolder.setExternalContext(externalContext);
                    FlowExecution flowExecution = getFlowExecution(controller, handler, externalContext);
    
                    flowExecution.getActiveSession().getScope().put(formObjectName, formObject);
                } finally {
                    ExternalContextHolder.setExternalContext(null);
                }
            }
        }
    
        /**
         * Retrieve FlowExecution
         * @param controller
         * @param handler
         * @param externalContext
         * @return FlowExecution
         */
        private static FlowExecution getFlowExecution(FlowController controller,
                FlowExecutorArgumentHandler handler, ExternalContext externalContext) {
            FlowExecutionRepository repository = ((FlowExecutorImpl) controller.getFlowExecutor())
                    .getExecutionRepository();
            FlowExecutionKey flowExecutionKey = repository.parseFlowExecutionKey(handler
                    .extractFlowExecutionKey(externalContext));
            FlowExecution flowExecution = repository.getFlowExecution(flowExecutionKey);
            return flowExecution;
        }
    
        /**
         * Retrieve FlowController
         * @param applicationContext
         * @return FlowController
         */
        private static FlowController getFlowController(ApplicationContext applicationContext) {
            FlowController controller = (FlowController) applicationContext.getBean("flowController");
            
            return controller;
        }
    }
    Problem:
    It seems that FlowExecutorArgumentHandler was obsolete/deprecated and removed.

    Want to achieve:
    would like to retrieve the view's model inside the controller.

    here's the webflow definition:
    Code:
    <view-state id="enterAnalysis" model="analysisView" view="view-analysis">
    	
    	<on-entry>
    		<evaluate expression="analysisService.execCreateAnalysisView(messageContext)" 
    		result="viewScope.analysisView"></evaluate>
    	</on-entry>
    	....
    	<transition on="back" to="finish" validate="false"/>
    	
    </view-state>
    Please guide me or give me some hints to investigate to achieve it.
    Thanks in advance.
Working...
X