Can I get the current webflow state within a Spring MVC controller?
Asked Answered
C

1

5

On the surface, a bit of a strange question! but I am creating a web app that uses both webflow and traditional Spring MVC controllers.

From one of the webflow views, a http request (ajax) is made from the client to a spring controller. When this was originally coded it didnt have much of a logical connection to the webflow, but now things have moved on and the controller could really do with knowing what screen (view-state) the request has come from.

My controller method signature looks like this:

@RequestMapping(value="/AjaxStuff", method=RequestMethod.POST)
public String ajaxStuff(@ModelAttribute("quote") QB2MotorQuote p_quote, BindingResult p_bindingResult, 
        HttpServletRequest p_req, Model p_model, DefaultMessageContext p_messages) {

I know from some of my webflow action classes that I can get the current state from the RequestContext object:

public Event checkDeclines(RequestContext p_ctx) throws Exception {
    // get the current state
    StateDefinition state = p_ctx.getCurrentState();

I've never really understood the 'voodoo' :) that Spring does where it can automagically inject parameters just by specifying them on the method signature (surely it can only inject things it knows about ??). I've tried simply changing the method signature of my controller method to inject in the RequestContext (in the vain hope that it will get injected), but it doesn't. It complains that RequestContext is an interface.

So, does anyone know how I can make my controller know about the current webflow state - either through injecting something into the controller method signature, or perhaps I can get it from the http request somehow (or session, which I can get from the request).

Any help with this very much appreciated.

Clercq answered 23/8, 2012 at 16:18 Comment(0)
C
7

inside your webflow view, you should have access to a variable ${flowRequestContext} that you can use in your ajax call.

you can just get the piece of information ${flowRequestContext.currentState} you want from it and add it as a parameter.

you cannot have the requestContext directly injected as your are not in a webflow environment. If you were, you could directly use RequestContext.getRequestContext(). Try calling it from your MVC controller and you will get null. Try from within a flow and you will get it.

Camilla answered 7/9, 2012 at 12:37 Comment(1)
Thanks for this, and sorry it's taken so long to accept your answer! Now I understand a bit more about how webflow and mvc work, I understand what you are saying. Thanks :)Clercq

© 2022 - 2024 — McMap. All rights reserved.