Dynamic Controller Plugin
2% of Grails users
Dependency :
compile ":dynamic-controller:0.4"
Summary
Supports controller mixins, where action closures are retrieved from various sources including existing controllers, files, database source, etc. Can also create full controllers dynamically.
Installation
grails install-plugin dynamic-controller
Description
See http://burtbeckwith.com/blog/?p=1041 for a writeup of the plugin's features.This plugin allows you to dynamically create controllers and add actions to existing controllers. The actions can be "copied" from existing controllers (e.g. instead of using url mappings), defined in a ControllerMixin (a new Artifact defined by the plugin), from a database, or any custom location you like as long as you implement the
ClosureSource interface.When you install the plugin, it creates the grails-app/controllerMixins folder. Controller mixins look just like controllers, but they only exist to be mixed into real controllers. You can use these to partition controllers into individual files, or create an initial controller that one or more plugins extend with their own mixins. A ControllerMixin must have a class name matching *ControllerMixin.You can define the destination controller for a controller mixin in one of two ways. One is a static controller property which specifies the class name of the controller to mix into. The other way is an attribute in Config.groovy, grails.plugins.dynamicController.mixins. A mixin doesn't affect the code or even bytecode - everything is done via Grails url registration, so really all that's being done is that in addition to existing /foo/** actions for FooController, new actions will be added under the /foo/ URL pattern.For example, suppose we have this simple controller in grails-app/controllers:package com.yourcompany.yourappclass FooController { def someAction = {
…
}
}grails-app/controllerMixins :package com.yourcompany.yourappclass SomeControllerMixin { static controller = 'com.yourcompany.yourapp.FooController' def someMixinAction = { … } }
package com.yourcompany.yourappclass SomeOtherControllerMixin { def someOtherMixinAction = {
…
}
}controller property):grails.plugins.dynamicController.mixins = [
'com.yourcompany.yourapp.SomeOtherControllerMixin': 'com.yourcompany.yourapp.FooController'
]- /foo/someAction
- /foo/someMixinAction
- /foo/someOtherMixinAction
controller property were com.yourcompany.yourapp.NewController and Config.groovy contained this:grails.plugins.dynamicController.mixins = [
'com.yourcompany.yourapp.SomeOtherControllerMixin': 'com.yourcompany.yourapp.NewController'
]- /foo/someAction
- /new/someMixinAction
- /new/someOtherMixinAction