Imagine this controller:
class exampleController{
def action1 = {}
def action2 = {}
def action3 = {}
def action4 = {}
def action5 = {}
}
I want to be able to return in all the action in this controller the same params. Imagining this:
def user = session.user
[user: user]
Is there any way of doing this, besides writing all the same code on all the actions? The session.user return params is just an example. I don't wanna really return it.
A simple solution is to put this code in a method and call it from each action
While this does involve some amount of repetition (invocation of the same method), it's a lot more obvious what's happening here. When debugging/testing a controller it's easy to forget about filters and interceptors, which can often lead to questions like
Use a filter - http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.6%20Filters - or an after interceptor - http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.1.5%20Controller%20Interceptors
I have a similar case, and I was modified the grails scaffolding for the controller's generator.
It is my suggestion, now if do you need another that sent a data to view then you can use interceptors.