What is the difference between nullable and blank constraints in Grails domain class?
Consider the following constraint defined within a domain class:
You will get the following error if you have a controller action for this domain:
This property blank is only applicable for a String field. The reason, the term blank does not sound good for non-string fields. To achieve the same for a non-string field, use nullable constraint here.
Package nulltest
Class Test1{
BigDecimal someValue
static constraints = {
someValue nullable:true
}
}
Note: By default, all domain class properties have an implicit nullable:false constraint.
Consider the following constraint defined within a domain class:
Package nulltest
Class Test1{
String someValue
static constraints = {
someValue blank:true
}
}
Grails while compling and running the application creates the fiels someValue to allow blank value.Class Test1{
String someValue
static constraints = {
someValue blank:true
}
}
You will get the following error if you have a controller action for this domain:
Property [someValue] of class [class nulltest.Test1] cannot be null
This property blank is only applicable for a String field. The reason, the term blank does not sound good for non-string fields. To achieve the same for a non-string field, use nullable constraint here.
Package nulltest
Class Test1{
BigDecimal someValue
static constraints = {
someValue nullable:true
}
}
0 comments:
Post a Comment