【问题标题】:Grails: Pass Params from Controller to Controller at end of WebflowGrails:在 Webflow 结束时将参数从控制器传递到控制器
【发布时间】:2013-01-28 10:34:44
【问题描述】:

是否可以在 Webflow 结束时在重定向中传递“参数”?基本上,这个变量或参数从控制器传递到控制器的目的是,如果流程已经完成,我希望在视图页面上有一个变量或 ${param.xyz} 可用。

 class Example1Controller{
    def startFlow = {
        begin {
        ....
        }
        ....
        ....    
        finished {
            action {
                flash.message = 'success'
            }
            redirect(controller: 'example2', action: 'myaccount', params: [author: "Stephen King"])
        } 
     }
  }

其他控制器

 class Example2Controller{
     def myaccount() {
         def here = $params.author
         return [me:here]
     }
 }

普惠制视图

 <html>
     <body>
         <g:if test="${params.me}">
             <p>This is what I want to display: **${me}**</p>
             <p>But it must come from the first controller, from the flow.</p>
         </g:if>
     </body>    
 </html>

基本上所有这些变量从控制器传递到控制器的目的是这样的。我希望只有在流程完成后才能在视图页面上使用变量或 ${param.}。

【问题讨论】:

    标签: grails groovy grails-2.0


    【解决方案1】:

    您可以使用hiddenField

    <g:hiddenField name="myField" value="myValue" />
    

    您可以将值从 Example1Controller 传递到 Example1Gsp(作为 hideenField),然后您可以从该 GSP 中获得 Example2Controller 的值。 p>

    【讨论】:

      【解决方案2】:

      如果我没记错的话,我们之前也这样做过,但是我们使用了流范围/流变量。比如:

      def myFlow = {
          fin {
              redirect: (controller: "xxx", action: "yyy", params: [someValue: flow.someValue])
          }
      }
      

      然后,在接收端,类似:

      def yyy = {
          [ aaa: params.someValue ]
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-04
        相关资源
        最近更新 更多