Announcement Announcement Module
No announcement yet.
SWF end of state forwarding to Spring MVC controller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SWF end of state forwarding to Spring MVC controller

    I have Spring MVC as the top level of my application, and certain user actions will trigger web-flows for a defined task (e.g. add a user). At the end of a webflow execution, I would like to do something like this:

    <end-state id="end" >
    <forward bean="${some spring mvc controller name}" method="${some method}" />

    I would like this to be a "forward" so that I can keep the attributes I set in the flow/request scope to be used by the target controller. Since the same webflow may be re-used in different context, the target controller should be somehow settable at run time (I use the ${} syntax just to illustrate this requirement).

    To make things a bit more complicated, I am using JstlTiles as my view.

    I've read the preveious posts, and it seems that this is possible to do, either in code or maybe by XML specification. However, I couldn't find an example on how to set this up. The FlowLauncher example is redirect, and it goes into another flow, rather than an MVC controller.



  • #2
    I'd do a redirect to the controller, passing it what you need as query parameters. You could create a custom ViewDescriptorCreator to do this.



    • #3
      Thanks, Keith.
      I tried to avoid redirect, but if that is the only way currently, I did the following, which sort of worked, but I hit another snag.

      In my flow.xml
      <endState id="end" view="redirect:/${flowScope.input}?submit=true" />

      In my flow action Controller, the last action I performed before the end state:

      ctx.getFlowScope().put("input", "");

      Somehow, the RedirectViewCreator failed to parse the EL, and I was redirected literally to ${flowScope.input}. How can I make this work?


      • #4
        Ugly workaround

        After playing with it for a while, I got one ugly workaround to do the forwarding from end of the web flow.

        Now I only have a marker end state:
        <endState id="end" />

        In my controller, the last action before the end State, I have the following code:
        ServletEvent evt = (ServletEvent)ctx.getSourceEvent();
        try {
        evt.getRequest().getRequestDispatcher(form.getEndV iew() + "?submit=true").forward(evt.getRequest(), evt.getResponse());
        } catch (Exception ex) { ex.printStackTrace(); }
        return success();

        This seems to be working, and I was forwarded to the correct controller. However, log shows an exception from FlowController:
        at ModelAndView(
        at org.springframework.web.flow.mvc.FlowController.ha ndleRequestInternal(
        at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(

        I hope this is OK. Anyway, this is ugly hacking. I wish that there is an implemented way to do same sort of thing more gracefully.
        It also seems to me that there is a lacking of a "ForwardAction" in Spring MVC design. Any reasons for this?



        • #5
          Yeah that's pretty ugly.

          I'm just not sure if a forward to a controller makes sense. The contract of webflow returns a ViewDescriptor (ModelAndView) to the caller, where the caller is responsible for rendering the appropriate view at that point. I guess we could have a property of the ViewDescriptor the caller could interpret to do a forward to another URL... not sure though.