tags:

views:

142

answers:

1

Hi,

I'm having problems to get browser's back button work properly on web flow. Version of grails is 1.1.2. Imagine example code:

def someFlow = {
   ...
   fillGroup {
      on("addMember"){
         ...
      }.to "fillMember"
   }
   fillMember {
      on("addMember") {
         ...
      }.to "fillMember"
      on("goToCart").to "showCart"
   }
   showCart {
      ...
   }
}

Now, I add group, several (>1) members and go to cart. Problem is that during filling the members the URL remains the same. URL execution parameter changes only if the state (view) changes.

So Firefox remembers fillMember pages as one page because the URL doesn't change. Therefore back button doesn't work properly. If I am on showCart and push back, I get to fillMember page. Further push of back button returns fillGroup. I need it to go through all the fillMember pages.

Is there any way to force Grails web flow to change the execution parameter even though I redirected to the same state? Or can I put my own parameter into the URL?

I found one pretty ugly way how to do that: use two fillMember states - fillMember1 and fillMember2, both doing the same thing, one redirects to another. But I need one more action state to be able to distinguish the actual state when hitting back and forward buttons. This construct works but I'd prefer easier way.

Thanks for any answers

Tom

+2  A: 

So far, the only solution I've found is the one I mentioned. Use two view states, both doing exactly the same thing, and one action state to hold some state information (it would be difficult to properly distinguish processed member without it). The code would be something like this:

def someFlow = {
   ...
   fillGroup {
      on("addMember"){
         ...
      }.to "fillMemberLogic"
   }
   fillMemberLogic {
      action {
         ...
         flow.stateinf += 1
         if(flow.stateinf%2 == 1)
            return gotoFillMember1()
         else
            return gotoFillMember2()
      }
      on("gotoFillMember1").to "fillMember1"
      on("gotoFillMember2").to "fillMember2"
   }      
   fillMember1 {
      on("addMember") {
         ...
      }.to "fillMemberLogic"
      on("goToCart").to "showCart"
   }
   fillMember2 {
      on("addMember") {
         ...
      }.to "fillMemberLogic"
      on("goToCart").to "showCart"
   }
   showCart {
      ...
   }
}

Since the view is being changed for every member, the execution parameter is also being changed and URL is distinct for every member. Firefox distinguishes viewed pages according to URL, so you can go back and forth through all the members using back and forward buttons.

Web flow is mapping URL with current state of flow object. Therefore it's easily possible to distinguish the current member you are processing after several back button pushes.

Tomik