I'm trying to set the date of birth of a person using jQuery Datepicker. However, all I get is that the Property dateOfBirth must be a valid Date
.
So, originally, my controller looks like this:
def update(Person personInstance) {
if (personInstance == null) {
// do Something
return
}
if (personInstance.hasErrors()) {
respond personInstance.errors, view: 'edit'
return
}
// do the rest
}
I figured out, that with jQuery I should use a SimpleDateFormat
object in order to generate a proper Date
object. Nevertheless, even if I directly assign a new Date
object to dateOfBirth
and subsequently validating the personInstance
domain object - like in the following code segment - I still get the Property dateOfBirth must be a valid Date
error.
def update(Person personInstance) {
if (personInstance == null) {
// do Something
return
}
// added code
personInstance.dateOfBirth = new Date()
personInstance.validate()
// added code
if (personInstance.hasErrors()) {
respond personInstance.errors, view: 'edit'
return
}
// do the rest
}
Thank you for any help :)
personInstance.clearErrors()
before callingpersonInstance.validate()
manually. You can see more about this in the documentation: grails.org/doc/2.2.x/ref/Domain%20Classes/clearErrors.html – Joshua Moore