When using Dynamic Scaffolding (
def scaffold = true;), the Controller scaffolding template found in
src/templates/scaffolding/Controller.groovy is not used. This template IS used when performing
grails generate-controller. And the View templates in this folder ARE used with Dynamic Scaffolding. This prevents mass customization of Controllers through Dynamic Scaffolding. It also breaks the expectations of the user; one works and one doesn't.
Attached an example project, where an attempt is made to add a 'Cancel' action and selection to scaffolded Controllers and Views. Files of note:
| grails-app/controllers/SomeObjectController.groovy |
Dynamic Scaffold Controller for SomeObject Domain Class |
| src/templates/scaffolding/Controller.groovy |
Expected template for Dynamic Scaffold Controllers; added cancel action |
| src/templates/scaffolding/create.gsp |
Added a Cancel button |
| src/templates/scaffolding/edit.gsp |
Added a Cancel button |
Running this project, both the Create and Edit views include the Cancel button added to the
create.gsp and
edit.gsp templates. But attempting to select either Cancel button results in the following Runtime Exception:
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.UnknownControllerException: No controller found for URI [/someObject/cancel]!
The included test (
grails test-app SomeObjectController) also fails. Both functionalities work if the Controller and Views are generated (
grails generate-all SomeObject). This confirms that the
cancel action added to the Controller template is not being included in the Dynamic Scaffolding, as expected.