Grails web flow

喜夏-厌秋 提交于 2019-12-06 03:35:58

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?

Maybe I don't understand the question, but can't you do

render (view:"showProducts", model:[products: Product.list()]

inside your controller?

You can try this (assuming you want go to checkout):

showProducts {
      on("checkout"){
           // do somethings here too if you like
           // then pass your data as below:
           [products: Product.list()]
      } .to "enterPersonalDetails"
      on("continueShopping").to "displayCatalogue"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!