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:
I call this controller using Ext.Ajax: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; } }
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?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 } });
Any hints are greatly appreciated!
Cheers,
jenner


Reply With Quote