How to get domain restriction value in Grails?

I have a text box whose length I would like to limit while limiting the maxSize 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 a value of 100 for the property bar. Is it possible?

+8
grails constraints
source share
3 answers

You must be able to:

 def maxBarSize = Foo.constraints.bar.getAppliedConstraint( 'maxSize' ).maxSize 
+13
source share

I had this problem in grails 3.1.8 and it has changed a bit. at least in gsp views I had to put this:

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

Hope this help! Hooray!

+5
source share

Check out the following code:

 def foo = new Foo(bar: "stuff") println foo.constraints.bar.maxSize 
0
source share

All Articles