Add the following lines in 'Config.groovy' file
grails.databinding.trimStrings=true grails.databinding.convertEmptyStringsToNull=true grails.databinding.dateFormats = ['yyyy-MM-dd HH:mm:ss.S', 'yyyy-MM-dd', "yyyy-MM-dd'T'hh:mm:ss'Z'"]
First line triming all string values on data binding to domain instance.
Second line convert all empty string to null.
And third line accept the date formats provided to convert it to date.
Or you can use those as following:
package com.pkm.test.domains import org.grails.databinding.BindingFormat class TestOne { Long id String name; String display; @BindingFormat("yyyy-mm-dd") Date created; static constraints = { display(nullable: true) } }
And from controller
params.name = "YES-Pritom K Mondal"; params.display = " "; params.created = "2014-02-27"; TestOne testOne = new TestOne(); DataBindingUtils.bindObjectToInstance(testOne, params) testOne.save(failOnError: true);
No comments:
Post a Comment