Grails Validation Gotcha on Dates
页面时间格式是02/23/2011
代码如下
def application = new Application(params) if (params?.accidentDate) { application.accidentDate = new Date().parse("MM/dd/yyyy", params.accidentDate) } else { application.accidentDate = null } application.validate() if (!application.hasErrors()){ application.save(failOnError:true) }
但是还是报错
应该是在defapplication=newApplication(params)的时候就已经有错误信息存在了
解决方法
def submitApplication(def params) { def application = new Application(params) application.clearErrors() if (params?.accidentDate) { application.accidentDate = new Date().parse("MM/dd/yyyy", params.accidentDate) } else { application.accidentDate = null } if (!application.hasErrors()){ application.save(failOnError:true) } application }
转自:http://jts-blog.com/?p=9269
相关推荐
hooopo 2014-07-12
80447518 2014-06-18
purpen 2014-05-23
jackyzhuyuanlu 2015-02-12
龙浩然 2015-11-06
daociyiyou 2016-11-07
coderbx 2013-03-11
yehell 2012-04-24
yeyedeyatou 2011-08-04
Ben的程序员生涯 2011-04-29
jieren 2010-02-18
carpenterworm 2009-04-03
trapeze 2008-06-06
掘井之路 2019-07-01