How do I pass an entire model from one controller to another without using a redirect?
Asked
Active
Viewed 6,200 times
2 Answers
11
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...

sparkyspider
- 13,195
- 10
- 89
- 133
-
3It's funny how soon we forget basic Servlet development when we start using frameworks. – Gregg Nov 19 '12 at 15:53
-
@Gregg Funny, more like scary! – sparkyspider Nov 19 '12 at 15:55
1
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