Unable to save domain objects until CRUD scaffold is used
I'm having the strangest problem with a controller in a Grails project. I am trying to do a simple update of a domain object. Here is a simplified version of the controller
def updateRecord = {
def foundHVT = Process.get(params.hvt)
foundHVT.summaryBy = params.summaryBy
foundHVT.catalogBy = params.catalogBy
foundHVT.editBy = params.editBy
foundHVT.produceBy = params.produceBy
foundHVT.correctedBy = params.correctedBy
// a bunch more of these
foundHVT.save(flush: true);
redirect (action:resource, id: params.hvt)
}
If I run the a new instance of the application of and use this controller to update an object, it doesn't work, the object doesn't save. It will look fine within the controller. I can, for example, 开发者_JAVA百科re-query the object and the changes are there, post save.
Now here's where it gets weird. If i use the preset scaffold edit controller and update/save an domain object -- and then switch back to this "updateRecord" controller it works FINE until i shut down the server it is working on?!?
I realize I am missing something very basic, but I can't find what it is. Any guidance would be most graciously appreciated.
DM
As HVGOTCODES noted Grails Clean seems to have fixed whatever weirdness was going on with this controller.
try putting a "def scaffold=true" in your controller if it does not already have the normal entry points.
Probably scaffolding save
fills some field that you don't.
Possible problems:
Do check
save()
result and renderfoundHVT.errors
the way Grails does. AddfailOnError: true
parameter tosave()
or just checkfoundHVT.hasErrors()
. Look atfoundHVT.errors.allErrors
for validation problems.Why not
foundHVT.properties = params
?What is there is no
foundHVT
?
精彩评论