Grails Web Stream

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

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 a way to do this separately from the previous view state with an action state that stores the model in the stream area?

Thanks Don

+3
source share
3 answers

Hmm, that has been a bit since I made the stream, and your example is simplified (just hope this is an example sake, hope).

- . , "", showProducts , , showproducts gsp POSTS. , showProducts, , 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 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)
}

?

+5

, ,

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

?

0

You can try this (provided that you want to move on to the design):

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"
}
0
source

Source: https://habr.com/ru/post/1710590/


All Articles