i want get default error message in view if some error occuring while insert an user. in controller i have 2 action:
def openPage() {
[user: new User(params)]
}
def save() {
User user = new User(params)
if (!user.save(flush:true)) {
redirect(view:'openPage', model:[user:user])
return
} else {
flash.message = "User saved"
redirect(action:'openPage')
}
}
and this is my gsp:
<g:hasErrors bean="${user }">
<g:eachError bean="${user }" var="error">
<li>${error } </li>
</g:eachError>
</g:hasErrors>
<g:if test="${flash.message }">
${flash.message }
</g:if>
<g:form action="save">
Name:<g:textField name="username"/>
<g:submitButton name="ok" value="Save"/>
</g:form>
but there’s something wrong and i can’t see any error if I sent no values. and this is my domain:
String username
static constraints = {
username(nullable:false, blank:false, unique:true)
}
what’s is wrong with my code? pls help. and must i use this method for catching errors or it’s better do it with if…else and try…catch?
Call render instead of redirect() method if save fails: