Currently when I need to share a method like processParams(params)
between different controllers, I use either inheritance or services.
Both solution has some inconvenients :
- With inheritance, you cannot use multiple inheritance which means that you need to have all of your controller utility methods in one place. And also, there is a bug in grails that does not detect any code changes in Base Controller classes in development mode (you need to restart the app)
- With services, you don't have access to all injected properties like params, session, flush...
So my question is : is there any other way to use some common methods accessible for multiple controllers ?
@Category
annotation to use the@Mixin
annotation. - You'd only need it when using the alternative methodSomethingController.mixin([MyControllerCategory])
(which requiresMyControllerCategory
to provide astatic
methodprintParams()
). The Groovy docs provide samples similar to yours, but this isn't necessary. - This misunderstanding might be due to the fact that the usage of categories has been undergoing an evolutionary process - once being clumsy by syntax, and now being superseded by the@Mixin
annotation. – Sestina