Reputation: 1
I need to add a controller action on runtime. In a plugin i add a dynamic method using doWithDynamicMethods but i can't invoke as an action.
I try using a mixin but it doesnt work. There is a bug with @grails.web.Mixin and is useless for me. And i'm not sure if i can call it as an action.
I understood that i need to add the @Action annotation to method that i create dynamiclly in the doWithDynamicMethods.
Should i use an AstTransformation. Or i miss something
Upvotes: 0
Views: 486
Reputation: 9705
I need to add a controller action on runtime.
No, you don't. You've got some other problem, and you think you can solve it by adding a controller action during runtime. But as you've learned, adding controller actions during runtime is really hard. You should solve your problem in some other way.
I don't know what your problem is, so I can't be too specific. But here's a generically useful trick. In UrlMappings.groovy
, you can do this:
"awesome/$stuff"(controller: 'awesome', action: 'doStuff')
And then in AwesomeController.groovy:
public doStuff(String stuff) {
// whatever arbitrary dynamic dispatch logic you want goes here
}
Hope that helps.
Upvotes: 1