grailsgroovygrails-2.0grails-domain-class

How to add inList constraints into a variable from different class?


My inList constraints for a variable in class grew bigger. I need an alternative. One approach that I feel may work is having a list in a separate class and call that as an inList constraint. For instance, instead of

variable(nullable: true, inList:['Yes','N'])

can I do something like

variable(nullable:true, inList:domainClass.list)?

Any helpful hints will be appreciated.


Solution

  • variable(nullable:true, inList:domainClass.list)

    That would only work if domainClass is the name of a class (since it begins with a lower case letter I expect it isn't) and list would need to be a static List literal. For example:

    class SomeClass {
        static final List SOME_VALUES = ['Yes', 'N']
    }
    

    Then you could do something like this:

    variable nullable:true, inList: SomeClass.SOME_VALUES
    

    I hope that helps.