Use size limit with Integer in Grails

The background document states that the size limit is:

Uses the Groovy range to limit the size of a collection or number or string length.

When I put a size limit on an integer, I get a warning

The [prop] property of TheClass domain class is of type [java.lang.Integer] and does not support the [size] constraint. This restriction will not be verified during verification.

Is the document wrong?

I know that I can use a range, but as a rule, it would be easier to indicate the number of digits in the number and not the actual value (for example, a social security number should have 7 digits or whatever, and not make a range of 1,000,000 - 9,999,999 )

+5
source share
4 answers

If you want the number of digits, make sure it is positive and has a certain length:

myInteger( validator: {
   return it > 0 &&  (it.toString.length) == 7
})
+2
source

I found the answer while searching for JIRA: http://jira.codehaus.org/browse/GRAILS-947 . The document is erroneous.

We do not need the minSize, maxSize restrictions and the size for numeric fields is larger, since this functionality is at the minimum, maximum and range limits, respectively. Therefore, we mark these restrictions (only for numeric fields) as deprecated at 0.5 and will remove it at 0.6.

It looks like a custom validator.

+2
source

max , myIntProp (max: 9999999)

+1

Jira , , - range .

, , size range.

0
source

All Articles