Grails web流程

Dón*_*nal 3 grails groovy spring-webflow

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

class BookController {
  def shoppingCartFlow = {
    showProducts {
      on("checkout").to "enterPersonalDetails"
      on("continueShopping").to "displayCatalogue"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

如果我想将数据模型传递[products: Product.list()]给showProducts.gsp,除了在视图状态之前加上一个将模型存储在流程范围内的动作状态之外,还有什么方法可以做到这一点吗?

谢谢,唐

bil*_*dev 5

嗯,这是因为我做了一个流程,你的例子是简单的(只是为了一个例子的缘故,我希望).

您遗漏的是流程中的初始操作.请记住,showProducts的"视图"流动作只是说明当showProducts gsp POSTS时要做什么.这是让你展示应该创建要在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)
}
Run Code Online (Sandbox Code Playgroud)

合理?