Thursday, April 29, 2010

Defining the order in which fields are generated on GRAILS Edit and Create forms

In the past I've spent a lot of time re-ording the fields on the Edit and Create views (forms) after GRAILS scaffolds them.  Then I started to notice that if I defined constraints within the model, the ordering was affected.  This lead me to start creating constraints for everything - whether they needed them or not.  So  yesterday I happened to be reading the documentation when I came across confirmation of this behavior, and an explanation that the constraint didn't actually have to do anything (which should have been obvious).  So in the following example, the last three constraints exist only for the purpose of defining their order (example from grails.org):

def constraints = {
firstName(size:0..30)
lastName(size:0..30)
title()
email()
releaseDate()
}


By including this the scaffolding will produce the order specified.  I don't have to muck with the view code, and I can regenerate the views without having to change them over and over.

This may be old news to many - but I never saw it in any of the tutorials.

No comments:

Post a Comment