Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom simple constraint grails

I would like to create a custom simple constraint (like display and editable) which I can use within my Domain class. Is it possible to extend ConstrainedProperty class?

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]
    }
}

Somebody familiar with this case?

like image 846
Matti van Aert Avatar asked Apr 12 '26 04:04

Matti van Aert


1 Answers

To create your own constraint:

  • extend 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 grails implementation of the size constraint for an example.

like image 97
ataylor Avatar answered Apr 16 '26 01:04

ataylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!