Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value of a domain constraint in Grails?

I have a text field whose length I would like to limit at the maxSize constraint of one of my domain classes.

So if I have a class foo:

class Foo {
    String bar

    static constraints = {
        bar(maxSize: 100)
    }
}

I would like to get that value of 100 for the property bar. Is this possible?

like image 379
Igor Avatar asked Apr 05 '12 14:04

Igor


2 Answers

You should be able to do:

def maxBarSize = Foo.constraints.bar.getAppliedConstraint( 'maxSize' ).maxSize
like image 72
tim_yates Avatar answered Oct 23 '22 10:10

tim_yates


I was having this issue in grails 3.1.8 and it has change a bit. at least in the gsp views I had to put this:

Foo.constrainedProperties ['bar']['maxSize']

Hope this help! Cheers!

like image 27
Octavio Garbarino Avatar answered Oct 23 '22 10:10

Octavio Garbarino