Lawrence Loh
Lawrence Loh

Reputation: 243

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

Upvotes: 0

Views: 93

Answers (1)

Joshua Moore
Joshua Moore

Reputation: 24776

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

Upvotes: 1

Related Questions