"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.2/grails-docs/src/test/resources/docs/guide/pages/addingConstraints.html" (2 Aug 2022, 59432 Bytes) of package /linux/www/grails-core-5.2.2.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.2.tar.gz project site itself.

(Quick Reference)

20.3 Adding Constraints

Version: 3.2.11

20.3 Adding Constraints

You can still use GORM validation even if you use a Java domain model. Grails lets you define constraints through separate scripts in the src/main/groovy/ directory. The script must be in a directory that matches the package of the corresponding domain class and its name must have a Constraints suffix. For example, if you had a domain class org.example.Book, then you would create the script src/main/groovy/org/example/BookConstraints.groovy\.

Add a standard GORM constraints block to the script:

constraints = {
    title blank: false
    author blank: false
}

Once this is in place you can validate instances of your domain class!