Results 1 to 2 of 2

Thread: Webflow sessionScope modifications using AJAX

  1. #1
    Join Date
    Oct 2005
    Posts
    27

    Default Webflow sessionScope modifications using AJAX

    Hi there,

    I know this topic has been discussed quite a few times already, and I've read the most threads about ajax/dwr/etc., but here's a problem I couldn't find a solution for:
    I need to store a flow scope variable using an XHR. I created a simple controller that would extract the current session and put the data into flowScope. However upon the next XHR the data I've put into flowScope in my previous request seems to be gone... here's the code:
    Code:
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.util.StringUtils;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.AbstractController;
    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.FlowSession;
    import org.springframework.webflow.execution.repository.FlowExecutionKey;
    import org.springframework.webflow.execution.repository.FlowExecutionRepository;
    import org.springframework.webflow.executor.FlowExecutorImpl;
    import org.springframework.webflow.executor.mvc.FlowController;
    import org.springframework.webflow.executor.support.FlowExecutorArgumentHandler;
    
    public class WebflowAjaxController
    extends AbstractController
    {
        
        private FlowController flowController;
        
        private FlowSession getActiveSession(HttpServletRequest request, HttpServletResponse response)
        {
            ExternalContext externalContext = new ServletExternalContext(getServletContext(), request, response);
            
            FlowExecutionRepository repository =
                ((FlowExecutorImpl) flowController.getFlowExecutor()).getExecutionRepository();
            
            FlowExecutorArgumentHandler handler = flowController.getArgumentHandler();
    
            ExternalContextHolder.setExternalContext(externalContext);
    
            FlowExecutionKey flowExecutionKey =
                repository.parseFlowExecutionKey(handler.extractFlowExecutionKey(externalContext));
            
            FlowExecution flowExecution = repository.getFlowExecution(flowExecutionKey);
            
            return flowExecution.getActiveSession();
        }
        
        private void closeContext()
        {
            ExternalContextHolder.setExternalContext(null);
        }
        
        public FlowController getFlowController()
        {
            return flowController;
        }
    
        
        public void setFlowController(FlowController flowController)
        {
            this.flowController = flowController;
        }
    
        @Override
        protected ModelAndView handleRequestInternal(HttpServletRequest request,
                                                     HttpServletResponse response)
        throws Exception
        {
            String methodName = request.getParameter("methodName");
            String flowExecutionKey = request.getParameter("_flowExecutionKey");
            response.setContentType("text/plain");
            if (!StringUtils.hasText(methodName) || !StringUtils.hasText(flowExecutionKey)) {
                response.sendError(500, "Method name and flowExecutionKey required!");
                return null;
            }
            FlowSession sess = getActiveSession(request, response);
            String tabView = sess.getScope().getString("tabView");
            System.out.println("got tabview: "+tabView);
            String par = request.getParameter("tabView");
            if (StringUtils.hasText(par)) {
                // set the tabView
                sess.getScope().put("tabView", par);
                System.out.println("new tabview: "+sess.getScope().getString("tabView"));
            }
            closeContext();
            return null;
        }
    }
    I call this controller using Ext.Ajax:
    Code:
    Ext.Ajax.request({
        url: RedaxSettings.appContext + '/cms/ajax/webflowUtils',
        success: Ext.emptyFn,
        failure: function(data) {alert("could not set new tab view")},
        params: {
            'methodName': 'setActiveTab',
            '_flowExecutionKey': '${flowExecutionKey}',
            'tabView': tab.tabView
        }
    });
    Judging by the debug output, the method is completed successfully, however the line sess.getScope().getString("tabView") always returns null no matter how often I'm running it - I mean even if on my first call it's null it should be set to some value on all subsequent calls, right? Is it even possible to modify the flowScope this way?

    Any hints are greatly appreciated!

    Cheers,
    jenner

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    You're probably updating the value in one continuation snapshot while retrieving it from another continuation snapshot.

    Here's a few interesting tips related to this:
    http://www.ervacon.com/products/swf/tips/tip2.html
    http://www.ervacon.com/products/swf/tips/tip1.html


    Erwin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •