Search code examples
grailsscaffolding

How to set the constraints of dynamic scaffolding project?


I'm very new to grails web application! Here is my domain class

package imocha.project

class Feedback {
    String name
    String email
    String type
    String remark

    static constraints = {
      name(blank:true)
      email(blank:true)
      type(blank:false)
      remark(blank:false)
    }
}

In my case, I just want to set only the type and remark can't be blank! But at the end, it set all for me.

Display adding screen


Solution

  • The reason for this is the default behavior for properties is nullable: false in a Grails project. Alter your constraints as follows:

    package imocha.project
    
    class Feedback {
        String name
        String email
        String type
        String remark
    
        static constraints = {
          name(nullable:true, blank:true)
          email(nullable:true, blank:true)
          type(blank:false)
          remark(blank:false)
        }
    }