Search code examples
grailsgroovyresponsegrails-controller

How can i trigger a onFailure event for g:formRemote?


I am using grails and i have a basic form remote

<g:formRemote name="add" onSuccess="close();" onFailure="dispayErrors();\"
                  url="[controller: ctx, action: 'insert']" method="POST" class="add">
 //Some inputs + submit button
</g:formRemote>

My question is what shoud the insert method return for so that onFailure is triggered? Thanx


Solution

  • Change the controller action (temporarily I presume) to

    def insert = {
        render status: HttpServletResponse.SC_INTERNAL_SERVER_ERROR
    
        // This also works
        //response.sendError HttpServletResponse.SC_INTERNAL_SERVER_ERROR
    }
    

    If you're using Grails 2.0 it is recommended to define your action as a method rather than a closure:

    def insert() {
        render status: HttpServletResponse.SC_INTERNAL_SERVER_ERROR
    }