1

I started using Grails web flow in order to implement a wizard.

checkStep {

        action {
            User user = springSecurityService.currentUser
            if (springSecurityService.loggedIn){
                def next = wizardService.getNextFlowStep(user)
                switch (next) {
                       case step1: 
                              step1()
                              break
    ...
                 }
         }
         on("step1").to "wizard_step1"
  } // checkStep
 wizard_step1() {
  ...
 }

I'd like to write the first step in more elegant way, such that based on "wizardService" the next step will be determined. I also preferred that the steps will be determined at run time, such that the actual step names and order may be reside in a database.

THanks

Tal
  • 194
  • 1
  • 8

1 Answers1

0

You want to use groovy's dynamic method invocation for something like this. I'm not sure if this will actually work inside of a webflow but it should look something like this....

        def next = wizardService.getNextFlowStep(user); // returns 'step1';
        "${next}"(); // you may have to use 'this."${next}"();'
Michael J. Lee
  • 12,278
  • 3
  • 23
  • 39
  • With this solution you will still need to explicitly enumerate all the `on('foo').to('bar')` options (though this could be done with a for loop if the event and state names follow some structure). I don't think there's a way around this, the structure of the flow (states and transitions) needs to be known at the point when the application starts up. [This question](http://stackoverflow.com/questions/11126683/grails-webflow-access-flow-scope-outside-of-action-or-transition-states/11168991#11168991) talks about a similar situation involving subflows. – Ian Roberts Jun 26 '12 at 14:53