Difference between nullable and blank

Posted by Anantha Narayanan On 12:10 AM No comments

What is the difference between nullable and blank constraints in Grails domain class? 

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.

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
 }
}
Note: By default, all domain class properties have an implicit nullable:false constraint.

0 comments:

Post a Comment

Recommended Post Slide Out For Blogger