问题
A few questions about the first state of a Grails web flow:
- Is it possible to have multiple start states?
- Is it possible for the first state to be an action state?
- Assuming the answer to (2) is no, what are my options for passing data to the first (view) state? I could store it in the session beforehand, but this isn't very appealing because I would need to take care of removing it myself. Ideally I'd like to store the data in flow scope before the first (view) state is displayed, but I don't see how this is possible
回答1:
You can have an action state as the first state in a webflow and you can pass parameters in to it as any other controller action and get them with 'params.paramName'.
def createNewSubscriptionFlow= {
initialState {
action {
...
Then grab the data you need and store in flow scope(Needs to be serializable!) as you state.
In answer to 1, I don't think you can have multiple start states but you could make your initial action state decide what state to move to.
Thanks,
Jim.
回答2:
You also can to use the onStart event
def csikszentmihalyiFlow = {
onStart doSomethingClosure
....
}
doSomethingClosure = {
def doSome = new Thing()
}
来源:https://stackoverflow.com/questions/7158042/grails-web-flow-first-state