Rendering command validation errors across a redirect
You can't send the command across in a redirect using params
. You have a couple options:
render()
in the error condition instead ofredirect()
ing:if(cpmc.hasErrors()) { render(view: 'profile', model: [creditProvider: cpmc]) }
This is the most common idiom for what you're doing.
Store the command in the session to persist it across the redirect:
if(cpmc.hasErrors()) { session.cpmc = cpmc redirect(...) } // and in your action def cpmc = session.cpmc ?: null render(view: 'profile', model: [creditProvider: cpmc])
This option is somewhat questionable. If not done correctly, you can pollute the session and leave objects hanging around, taking up memory. If done correctly, though, it can be a decent way to implement a post-redirect-get.