1

I want to send validation errors back to a different page (add), so I have this for my save action:

@Transactional(readOnly = false)
def save(AddDomainCommand command) {

    if (command.validate() && session.isLoggedIn && session.publisher) {
        // do some stuff
        return redirect(controller: 'Widget', action: 'generate')
    }

    log.info("Validation failed for $command")
    respond view: "add", model: [domain: command]
}

It errors with javax.servlet.ServletException: Could not resolve view with name 'save' in servlet with name 'grailsDispatcherServlet'

If I print the response from respond, I get null! So that explains why it's going to save, because that's the convention for the action's name.

I need it to go back to the view it came from (add.gsp), yet grails respond is null and thus defaulting to save.gsp. Any ideas?

Alex
  • 8,093
  • 6
  • 49
  • 79

1 Answers1

2

respond uses a different syntax and is used when you want to be able to support multiple client types based on mime type, e.g. JSON and/or XML for a REST client and HTML/GSP for a regular browser client. If you just want to use add.gsp to render HTML, use render:

render view: 'add', model: [domain: command]
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156