How do I pass an entire model from one controller to another without using a redirect?
I struggled with this for quite a while, so decided to answer my own question...
It's quite possible with the forward
method. Unlike the chain
method, the documentation doesn't mention the model
attribute, but [in grails 2.1.1 at least] it is actually supported.
In Controller One:
def model = [
firstname: params.firstname,
lastname: params.lastname
]
forward(controller:"controllerName",action:"index", model:model)
In Controller Two:
render (view: "/page.gsp")
In page.gsp
Welcome ${firstname} ${lastname},
...
Simple as that...
If you want to pass the whole object (which contains their own methods), refer to my answer on Best way to pass objects between controller actions in grails
The key is 1) using "chain action" in source action, 2) using chainModel in target action
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With