views:

111

answers:

1

Say, I have this type of webflow:

def myFlow = {
    state1 {
    }
    on("next").to("stateAct")

    stateAct {
        action {
            ... DB stuff ...
        }
    }
    on("success").to("state2")

    state2 {
    }
    on("prev").to("state1")
}

Now, the contents of "stateAct" is common between state1 and state2. Meaning, if I press "next" from state1, I need to pass by stateAct before I can go to state2 (which is the current implementation) and if I press "prev" in state2, I need it to pass by stateAct before it goes to state1. Obviously, in the sample webflow above, it doesn't do the latter.

So, my question is, is there a way to detect in stateAct who called it (state1 or state2) so that I can redirect accordingly on "success"? Or something similar to that behavior?

Thanks!

-Lee

A: 

Why not store this info in a flow-scoped variable? Something like:

def myFlow = {
    state1 {
      on("next") {
          flow.originator = 'state1'
      }.to("stateAct")
    }
    stateAct {
        action {
            if (flow.originator == 'state1') do something
            if (flow.originator == 'state2') do something else
        }
    }
    on("success").to("state2")

    state2 {

      on("prev"){
        flow.originator = 'state2'
      }.to("stateAct")
}
Mike Sickler
Thanks, my first time to do webflows so I'll try this out =) However, as a follow-up question, if state2 enters stateAct via on prev and it finishes, wouldn't it go back to state2 because of the on("success").to("state2") line?
callie16
Yes, you'd want to modify stateAct to redirect the user to different places, depending on where they came from.
Mike Sickler
Hmm... ok, I'll try it out =) Thanks!
callie16