Grails Web流程 [英] Grails web flow

查看:100
本文介绍了Grails Web流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法将模型数据传递给视图状态?考虑以下示例视图状态:

  class BookController {
def shoppingCartFlow = {
showProducts {
on(checkout)。toenterPersonalDetails
on(continueShopping)。todisplayCatalogue
}
}
}

如果我想传递数据模型 [products:Product.list()] showProducts.gsp,有没有办法做到这一点,除了在视图状态之前使用将模型存储在流程范围中的操作状态?



感谢,
Don

解决方案

有一点,因为我做了一个流程,你的例子是简单的(仅仅是为了一个例子的缘故,我希望)。



你缺少的是什么流。请记住,showProducts的视图流动操作只是说明在showProducts gsp POSTS时该怎么做。这是SENT你显示的动作,应该创建用于showProducts.gsp的模型。

  def ShoppingCartFlow = {
initialize {
action {//注意这是一个ACTION流任务
//执行一些代码
[model:modelInstance] //这个模型将用于showProducts.gsp

on(success)。toshowProducts
//上述行将您发送至showProducts.gsp
}

showProducts {
//注意缺少动作{}表示这是一个VIEW流任务
//当您单击showProducts.gsp
on(checkout)中的操作按钮时, .toenterPersonalDetails
on(continueShopping)。displayCatalogue
}

//等等(你需要一个enterPersonalDetails任务,
// displayCatalogue任务,它们
//应该都是ACTION任务)
}

有意义吗?


Is there any way to pass model data to a view state? Consider the following example view state:

class BookController {
  def shoppingCartFlow = {
    showProducts {
      on("checkout").to "enterPersonalDetails"
      on("continueShopping").to "displayCatalogue"
    }
  }
}

If I want to pass the data model [products: Product.list()] to showProducts.gsp, is there any way to do this apart from preceding the view state with an action state that stores the model in flow scope?

Thanks, Don

解决方案

Hmm, it's been a bit since I did a flow, and your example is simplistic (just for being an example's sake, I hope).

What your missing is the initial action in the flow. Keep in mind that a "view" flow action as your showProducts is just says what to do when your showProducts gsp POSTS. It's the action that SENT you to showProducts that should create the model to be used in showProducts.gsp

def ShoppingCartFlow = {
   initialize {
       action {  // note this is an ACTION flow task
           // perform some code
           [ model: modelInstance ] // this model will be used in showProducts.gsp
       }
       on ("success").to "showProducts"      
       // it's the above line that sends you to showProducts.gsp
   }

   showProducts {
        // note lack of action{} means this is a VIEW flow task
        // you'll get here when you click an action button from showProducts.gsp
      on("checkout").to "enterPersonalDetails"
      on("continueShopping").to "displayCatalogue"
   }

   // etc. (you'll need an enterPersonalDetails task, 
   // displayCatalogue task, and they
   // should both be ACTION tasks)
}

Make sense?

这篇关于Grails Web流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆