Search code examples
grailshttp-redirectspring-webflow

Grails Web Flow: Redirect to the webflow from another controller action?


Here's what I think I want to do:

class MyController {
    def goToWizard = {
        if (params.option1)
            redirect actionName:'wizard1', params:params
        if (params.option2)
            redirect actionName:'wizard2', params:params
    }
    def wizard1Flow = {
       start {
          action {
              // put some values from the params into flow scope
              [thingsThatGotPassedIn:params.thingsThatGotPassedIn]
          }
          on('success').to 'nextThing...'
       }
       // wizard 1 implementation...
       //...
       done {
          redirect view:'somewhereElse'
       }
    }
    def wizard2Flow = {
       start {
          action {
              // put some values from the params into flow scope
              [thingsThatGotPassedIn:params.thingsThatGotPassedIn]
          }
          on('success').to 'nextThing...'
       }
       // wizard 2 implementation...
       //...
       done {
          redirect view:'somewhereElse'
       }
    }
}

I've tried something like this, but I don't seem to ever get into the webflow. Is this a valid approach?

The reason for all this is that I have a gsp that looks like so (a form with 2 submit buttons inside, each one should trigger a different webflow)

<g:form action="goToWizard">
    ...
    <g:submitButton name="wiz1" value="Goto Wizard1"/>
    <g:submitButton name="wiz2" value="Goto Wizard2"/>
</g:form>

There are some input elements inside the form that I want to pass the values of into whichever webflow gets called. I'd rather just have the form submit call the appropriate webflow directly (the way all the examples that I've seen work), but there are two webflows, and only one form. How can I accomplish this?

I'm also interested in alternative implementations, if you think this is the wrong way. I'm new to webflows in grails.


Solution

  • Take a look at actionSubmit tag in grails documentation. I think, you should use actionSubmit instead of submitButton

    actionSubmit creates a submit button that maps to a specific action, which allows you to have multiple submit buttons in a single form. Javascript event handlers can be added using the same parameter names as in HTML.

    By this approach, You no need to mention action in form tag, i.e. No need to make a check in goToWizard. You can send contents directly to your particular action.
    Is this the solution to your problem?