In one of the sessions in SpringOne2GX, there was a session on Uber-Scaffolding by Jean Barmarsh. The session was quite incredible and opened up a world of possibilities. We all know that the scaffolded code generated by grails is modifiable if we install the base templates. This is done simply by saying:
The above command will create the following directory structure in the application’s src folder
Now there are a lot of things that we may need to modify in the grails templates, the pagination size being one. So, the first change that I did was made the “max” parameter in controller be Config driven simply by replacing :
params.max = Math.min(params.max ? params.int('max') : 10, 100)
int pageSize = grailsApplication.config.grails.scaffolds.pageSize ?: 10 params.max = Math.min(params.max ? params.int('max') : pageSize, 100)
This was the simplest thing that was done.
In order to use the changed scaffolding, there are two ways of doing this:
grails generate-all MyDomainClass
def scaffold = MyDomainClass
Note: When playing around with grails templates, be very careful not to format this code using an IDE. The formatting will add unwanted spaces and the grails create-*/generate-* commands will start failing or produce wrong/unusable files.
Will be back with more
You May Also Like
Get latest articles straight to your inbox. Enter your email address below: