With Grails 3 (I don't know if this worked before), you can use flash to do this. According to the documentation, the flash will be "cleared at the end of the next request."
I like to use a template like this:
def save(MyDomain myDomain) { if (myDomain.validate()) { myDomain.save() } else { flash.errors = myDomain.errors } redirect(action: 'edit', id: myDomain.id) } def edit(MyDomain myDomain) { if (flash.errors) { myDomain.errors = (Errors) flash.errors } return [myDomain: myDomain] }
I do not like to use render() for this kind of error handling, because it makes the URLs displayed in the browser incompatible with the displayed page. This is broken when users set bookmarks, for example.
Michael kanis
source share