Grails Web Flow:从另一个控制器操作重定向到 Webflow?

发布于 2024-10-20 09:37:44 字数 1509 浏览 3 评论 0原文

这就是我认为我想做的事情:

class MyController {
    def goToWizard = {
        if (params.option1)
            redirect actionName:'wizard1', params:params
        if (params.option2)
            redirect actionName:'wizard2', params:params
    }
    def wizard1Flow = {
       start {
          action {
              // put some values from the params into flow scope
              [thingsThatGotPassedIn:params.thingsThatGotPassedIn]
          }
          on('success').to 'nextThing...'
       }
       // wizard 1 implementation...
       //...
       done {
          redirect view:'somewhereElse'
       }
    }
    def wizard2Flow = {
       start {
          action {
              // put some values from the params into flow scope
              [thingsThatGotPassedIn:params.thingsThatGotPassedIn]
          }
          on('success').to 'nextThing...'
       }
       // wizard 2 implementation...
       //...
       done {
          redirect view:'somewhereElse'
       }
    }
}

我已经尝试过类似的事情,但我似乎从未进入过网络流。这是一个有效的方法吗?

这一切的原因是我有一个看起来像这样的 gsp(一个表单,里面有 2 个提交按钮,每个按钮都应该触发一个不同的 webflow)

<g:form action="goToWizard">
    ...
    <g:submitButton name="wiz1" value="Goto Wizard1"/>
    <g:submitButton name="wiz2" value="Goto Wizard2"/>
</g:form>

表单中有一些输入元素,我想将它们的值传递到其中的任何一个webflow 被调用。我宁愿让表单提交直接调用适当的网络流(这是我见过的所有示例的工作方式),但有两个网络流,并且只有一个表单。我怎样才能做到这一点?

如果您认为这是错误的方式,我也对替代实现感兴趣。我是 Grails 中的网络流新手。

Here's what I think I want to do:

class MyController {
    def goToWizard = {
        if (params.option1)
            redirect actionName:'wizard1', params:params
        if (params.option2)
            redirect actionName:'wizard2', params:params
    }
    def wizard1Flow = {
       start {
          action {
              // put some values from the params into flow scope
              [thingsThatGotPassedIn:params.thingsThatGotPassedIn]
          }
          on('success').to 'nextThing...'
       }
       // wizard 1 implementation...
       //...
       done {
          redirect view:'somewhereElse'
       }
    }
    def wizard2Flow = {
       start {
          action {
              // put some values from the params into flow scope
              [thingsThatGotPassedIn:params.thingsThatGotPassedIn]
          }
          on('success').to 'nextThing...'
       }
       // wizard 2 implementation...
       //...
       done {
          redirect view:'somewhereElse'
       }
    }
}

I've tried something like this, but I don't seem to ever get into the webflow. Is this a valid approach?

The reason for all this is that I have a gsp that looks like so (a form with 2 submit buttons inside, each one should trigger a different webflow)

<g:form action="goToWizard">
    ...
    <g:submitButton name="wiz1" value="Goto Wizard1"/>
    <g:submitButton name="wiz2" value="Goto Wizard2"/>
</g:form>

There are some input elements inside the form that I want to pass the values of into whichever webflow gets called. I'd rather just have the form submit call the appropriate webflow directly (the way all the examples that I've seen work), but there are two webflows, and only one form. How can I accomplish this?

I'm also interested in alternative implementations, if you think this is the wrong way. I'm new to webflows in grails.

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

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

发布评论

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

评论(1

夜灵血窟げ 2024-10-27 09:37:44

查看 grails 文档中的 actionSubmit 标记。我认为,您应该使用 actionSubmit 而不是 submitButton

actionSubmit 创建一个映射到特定操作的提交按钮,这允许您有多个提交单一表单中的按钮。可以使用与 HTML 中相同的参数名称来添加 Javascript 事件处理程序。

通过这种方法,您无需在 form 标记中提及 action,即无需在 goToWizard 中进行检查。您可以将内容直接发送到您的特定操作。
这是您问题的解决方案吗?

Take a look at actionSubmit tag in grails documentation. I think, you should use actionSubmit instead of submitButton

actionSubmit creates a submit button that maps to a specific action, which allows you to have multiple submit buttons in a single form. Javascript event handlers can be added using the same parameter names as in HTML.

By this approach, You no need to mention action in form tag, i.e. No need to make a check in goToWizard. You can send contents directly to your particular action.
Is this the solution to your problem?

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