Grails WebFlow State Name

2020-04-15 12:10发布

问题:

Grails noob here...

How do I get the state name inside a Grails webflow state? I'm prototyping a mobile app using Grails WebFlow and jQueryMobile. Because it's a mobile app comprised primarily of lists, I manage the back events using a stack like this:

class myController {
    def myFlow {
        start {
            action {
                flow.states = []
                [ ... ]
            } 
            on("success").to "state0"
        }

        state0 {
            on("back").to "home"
            on("event") {
                flow.states << "state0"
            }.to "state1"
        }

        state1 {
            on("back").to { flow.states.pop() }
            on("event") {
                flow.states << "state1"
            }.to "state2"
        }

        state2 {
            on("back").to { flow.states.pop() }
        }

        home {
            redirect( ... )
        }
    }
}

This works, but I'd like to replace the hard coded state name strings in lines like flow.states << "state#" with an expression if there's a way to do it.

EDIT: I'll accept answers that explain why this can't be done.

回答1:

Try using the RequestContext and/or the FlowExecutionContext? e.g. flowExecutionContext.currentState.id