Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails Scaffolding - define possible values for this property of a domain class

I am new to Grails. I have a Person domain class as :

class Person {
    String firstName
    String lastName
    String gender
    Date dateOfBirth
}

And wondering if I can define possible values for a property - say gender as {M, F, U} so that these three values will be listed in combo box when using dynamic scaffolding for Person controller.

Here I just wanted to know if there is such feature in Grails framework? If such feature exists , then how can I use it?

like image 787
gtiwari333 Avatar asked Jul 08 '12 04:07

gtiwari333


1 Answers

From the documentation http://grails.org/doc/latest/guide/scaffolding.html, you should be able to use an inList constraint:

class Person {
    String firstName
    String lastName
    String gender
    Date dateOfBirth

    def constraints = {
        gender( inList: ["M", "F", "U"])
    }
}

This should scaffold to a select list for the gender field, depending on the version of Grails you're using. 2.0+ definitely does this.

like image 109
billjamesdev Avatar answered Sep 18 '22 10:09

billjamesdev