I am new to Grails, I tried to save domain object by calling save() in my *service.groovy as shown below
render " ${user.username}"
render " ${user.email}"
render " ${user.password}"
def savedUser = user.save(flush: true)
if(savedUser!=null) {
return savedUser
} else {
return user
}
The render shows all elements have the values which have been passed from controller. but an NullPointerexception is thrown in save(). the actual error got is
ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [POST]
Validation error might have occurred, but I checked all validation error in controller by using command class.
How can avoid the exception here?
user.save(flush: true, failOnError: true). - dmahapatrograils.gorm.failOnError = truein yourConfig.groovy. fail early... - cfrickfailOnError. Exceptions are expensive and even more so in Groovy, and it's not a good idea to generate unnecessary exceptions for non-exceptional cases like user error when filling out forms and submitting data. Just check if there was a validation error - it's basically the same code as a try/catch and doesn't incur the runtime cost of filling in all those stack frames which aren't used. - Burt Beckwith