Custom simple grails constraints
I would like to create a custom simple constraint (like display and edit) that I can use in the Domain class. Can the ConstrainedProperty class be extended?
class City {
String title
BigDecimal latitude
BigDecimal longitude
Country country
static constraints = {
title ( blank: false, customConstraint: true ) // filter can be also be applied as attributes: [customConstraint: true]
}
}
Anyone familiar with this case?
+3
source to share
1 answer
To create your own constraint:
- expand
org.codehaus.groovy.grails.validation.AbstractConstraint
- register the class as a constraint by calling
org.codehaus.groovy.grails.validation.ConstrainedProperty.registerNewConstraint
Take a look at the implementation of font size constraints for an example.
+3
source to share