浏览器后退按钮的 Grails Web 流量问题

发布于 2024-08-16 18:54:36 字数 824 浏览 6 评论 0原文

我在使浏览器的后退按钮在网络流上正常工作时遇到问题。 grails 的版本是 1.1.2。 想象一下示例代码:

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

现在,我添加组、几个 (>1) 成员并转到购物车。问题是在填充成员期间 URL 保持不变。仅当状态(视图)发生变化时,URL 执行参数才会发生变化。

因此 Firefox 会将 fillMember 页面记住为一页,因为 URL 不会更改。因此后退按钮无法正常工作。如果我在 showCart 上并向后推,我就会进入 fillMember 页面。进一步按下后退按钮将返回 fillGroup。我需要它来浏览所有 fillMember 页面。

即使我重定向到相同的状态,是否有任何方法可以强制 Grails Web 流更改执行参数?或者我可以将自己的参数放入 URL 中吗?

我发现了一种非常丑陋的方法:使用两个 fillMember 状态 - fillMember1 和 fillMember2,两者都做同样的事情,一个重定向到另一个。但我还需要一种动作状态,以便能够区分按下后退和前进按钮时的实际状态。这种结构有效,但我更喜欢更简单的方法。

感谢

汤姆的任何回答

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你手 2024-08-23 18:54:36

到目前为止,我找到的唯一解决方案就是我提到的那个。使用两个视图状态,两者都执行完全相同的操作,并使用一个操作状态来保存一些状态信息(如果没有它,将很难正确区分已处理的成员)。代码如下所示:

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 {
      ...
   }
}

由于每个成员的视图都会更改,因此执行参数也会更改,并且每个成员的 URL 都是不同的。 Firefox 根据 URL 区分查看的页面,因此您可以使用后退和前进按钮来回浏览所有成员。

Web 流正在将 URL 与流对象的当前状态进行映射。因此,在按下几次后退按钮后,可以轻松区分您正在处理的当前成员。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文