Reputation: 31
I am creating a project in my ProjectController and it should be saved after being created. But instead it gives me the following exception:
Class java.lang.ClassCastException
Message com.everyonecounts.padre.ProjectController$_closure1 cannot be cast to javax.servlet.ServletRequest
Here is the code for my save method:
def save() {
log.debug(params)
def projectInstance = new Project(params)
if (!projectInstance.save(flush: false)) {
log.debug("save failed")
render(view: "create", model: [projectInstance: projectInstance])
return
}
}
Stack trace tells me that the error occurs at the render line.
Upvotes: 0
Views: 1432
Reputation: 50245
After a close look, I see that you actually are checking for errors in save
instead of a successful save. Do you need to check for an unsuccessful save or successful?
def save() {
log.debug(params)
def projectInstance = new Project(params)
//If save was successful then the if block will not be executed.
if (!projectInstance.save(flush: false)) {//Returns true on successful save.
log.debug("save failed")
render(view: "create", model: [projectInstance: projectInstance])
return
}
//There is nothing to render here in case the save was successful.
//you would need something like below on save success
//render(view: "create", model: [projectInstance: projectInstance])
}
Upvotes: 1