Showing posts with label Grails dynamic scaffolding view package Groovy. Show all posts
Showing posts with label Grails dynamic scaffolding view package Groovy. Show all posts

Thursday, March 20, 2008

Customizing dynamic scaffolding views

Let me open this first post by apologizing in advance for the silly things I will write over the coming months. I expect a good proportion of the posts I make on this blog will report things that were a secret to me but not to anyone else. This will likely happen because I,
  • Fail to read the correct piece of documentation, or,
  • Mis-read the appropriate documentation, or,
  • Search the mailing lists and Jira with the wrong keywords, or,
  • Lack talent and basic common sense
Without further ado lets dive into the first secret I've stumbled upon.

I'm writing a Grails read-only front end to a legacy database. I have written a proprietary security plug-in and I'm pretty happy that my application will not allow update or other unauthorized access to the database. I have dozens of tables mapped to Grails domain classes and the dynamic scaffolding feature that lets me not have to generate and maintain views saves me a huge amount of work.

However, the dynamic scaffolding views contain buttons that purport to allow users to add, update and delete data. My security plug-in won't let them do any database updates but it is a bit ugly having these superfluous buttons everywhere. As I really did not want to generate and then edit views for each domain class I started to search around.

Fairly quickly I stumbled upon this bit of code in the Package.groovy build script,

target(packageTemplates: "Packages templates into the app") {
--Ant.mkdir(dir:scaffoldDir)
--if(new File("${basedir}/src/templates/scaffolding").exists()) {
----Ant.copy(todir:scaffoldDir, overwrite:true) {
------fileset(dir:"${basedir}/src/templates/scaffolding", includes:"**")
----}
--}
--else {
----Ant.copy(todir:scaffoldDir, overwrite:true) {
------fileset(dir:"${grailsHome}/src/grails/templates/scaffolding", includes:"**")
----}
--}
}


How cool is this. By taking a copy of of the default dynamic scaffolding views in the Grails src directory and putting them in my own src directory I was able to create my own customized dynamic scaffolding views which did not contain add, update or delete buttons.

Mission accomplished! Thank you Grails guys and girls for such a neat feature.