I'm aware that it's a bug, but calling validate() on a domain class overwrites any rejects that are put in before:
def save = {
def assignment = new Assignment(params)
assignment.errors.reject("assignment.error")
// Save
if (assignment.validate()) {
//rejected error is gone
assignment.save()
redirect action: "list"
}
else {
//render errors
render view: "create", model: [instance: assignment]
}
}
So, until this issue is fixed (it's been around since grails 1.0 and it's almost 2.0 now), is there any smart workaround to preserve rejects and use the if validate() then save() paradigm at once?
It's not a bug, it's by design. By calling validate() you're asking for the validation process to start over again. If you want manual reject() calls to be included in the errors, put them after the call to validate().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With