grails 没有错误并验证为 true 但不保存。
我有一个调用 .save() 的方法,但不将数据保存在数据库中。我试过ff:
- 称为 FailOnError: true 但不显示任何失败的内容
- validate(),它确实返回 true
- hasErrors(),它确实返回 true put
- put return objectInstance 并显示该值已更改
- 设置冲洗:假
但是在上述所有内容中没有显示任何验证失败,它仍然不会保存在数据库中。我尝试记录休眠状态,但它没有显示该实例的“更新”方法。Mayeb 这就是为什么没有更新发生的原因。但我最大的问题是为什么?为什么在没有错误或任何东西的情况下不调用更新?我错过了什么。谢谢。
这是我的控制器代码:
def obpViewFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
.....
}
on("success").to 'obpViewCase'
on(Exception).to 'obpViewCase'
}
obpViewCase {
on("edit").to 'edit'
on("cancel").to 'cancel'
}
edit {
redirect( action:"obpEdit", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}def obpViewFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
if (params.created) {
flash.message = "OBP Case has been successfully saved."
}
}
on("success").to 'obpViewCase'
on(Exception).to 'obpViewCase'
}
obpViewCase {
on("edit").to 'edit'
on("cancel").to 'cancel'
}
edit {
redirect( action:"obpEdit", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
def obpEditFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
flow.appDate = caseInstance.applicationDate
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
// get the following list to populate dropdown fields
def residenceTypeList = ResidenceType.list()
def visualImpairmentCauseList = VisualImpairmentCause.list()
def referralSourceList = ReferralSource.list()
[residencesType: residenceTypeList, visualImpairmentsCause: visualImpairmentCauseList, referralSources: referralSourceList]
}
on("success").to 'obpEditCase'
on(Exception).to 'obpEditCase'
}
obpEditCase {
on("save") {
this.bindObpFields(flow, caseService, params)
if (!this.bindAndValidateConstraints(flow, caseService, params)) {
flow.olderBlindInstance = flow.obpCaseInstance.olderBlind
return error()
}
}.to 'save'
on("cancel").to 'cancel'
}
save {
action {
def obpCaseInstance = flow.obpCaseInstance
try {
HttpSession theSession = request.getSession();
def obpCase = caseService.saveUpdateObpCase(obpCaseInstance, theSession.currentUser)
}
catch(Exception ie) {
flow.exceptionMessage = ie.getMessage()
throw ie
}
}
on("success").to 'finish'
on(Exception).to 'handleError'
}
finish {
def obpViewFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
if (params.created) {
flash.message = "OBP Case has been successfully saved."
}
}
on("success").to 'obpViewCase'
on(Exception).to 'obpViewCase'
}
obpViewCase {
on("edit").to 'edit'
on("cancel").to 'cancel'
}
edit {
redirect( action:"obpEdit", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
def obpEditFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
flow.appDate = caseInstance.applicationDate
ObpCase obpCaseInstance = caseService.getObpCase(caseInstance)
// set obpCaseInstance to flow scope, instance for view state
flow.obpCaseInstance = obpCaseInstance
// get the following list to populate dropdown fields
def residenceTypeList = ResidenceType.list()
def visualImpairmentCauseList = VisualImpairmentCause.list()
def referralSourceList = ReferralSource.list()
[residencesType: residenceTypeList, visualImpairmentsCause: visualImpairmentCauseList, referralSources: referralSourceList]
}
on("success").to 'obpEditCase'
on(Exception).to 'obpEditCase'
}
obpEditCase {
on("save") {
this.bindObpFields(flow, caseService, params)
if (!this.bindAndValidateConstraints(flow, caseService, params)) {
flow.olderBlindInstance = flow.obpCaseInstance.olderBlind
return error()
}
}.to 'save'
on("cancel").to 'cancel'
}
save {
action {
def obpCaseInstance = flow.obpCaseInstance
try {
HttpSession theSession = request.getSession();
def obpCase = caseService.saveUpdateObpCase(obpCaseInstance, theSession.currentUser)
}
catch(Exception ie) {
flow.exceptionMessage = ie.getMessage()
throw ie
}
}
on("success").to 'finish'
on(Exception).to 'handleError'
}
finish {
redirect( action:"obpView", controller:"olderBlind", params:["created": "created", caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
handleError() {
action {
return success()
}
on("success").to 'obpEditCase'
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
redirect( action:"obpView", controller:"olderBlind", params:["created": "created", caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
handleError() {
action {
return success()
}
on("success").to 'obpEditCase'
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
}
def obpEditFlow = {
start {
action {
def caseInstance = CmCase.get(params.caseId as Long)
....
}
on("success").to 'obpEditCase'
on(Exception).to 'obpEditCase'
}
obpEditCase {
on("save") {
this.bindObpFields(flow, caseService, params)
if (!this.bindAndValidateConstraints(flow, caseService, params)) {
flow.olderBlindInstance = flow.obpCaseInstance.olderBlind
return error()
}
}.to 'save'
on("cancel").to 'cancel'
}
save {
action {
def obpCaseInstance = flow.obpCaseInstance
try {
HttpSession theSession = request.getSession();
def obpCase = caseService.saveUpdateObpCase(obpCaseInstance, theSession.currentUser)
}
catch(Exception ie) {
flow.exceptionMessage = ie.getMessage()
throw ie
}
}
on("success").to 'finish'
on(Exception).to 'handleError'
}
finish {
redirect( action:"obpView", controller:"olderBlind", params:["created": "created", caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
handleError() {
action {
return success()
}
on("success").to 'obpEditCase'
}
cancel {
redirect( action:"obpView", controller:"olderBlind", params:[caseId: flow.obpCaseInstance.olderBlind.cmCaseIdCmCase])
}
}
这是我的保存服务代码
def CmCase saveUpdateCase(CmCase caseInstance, Users currentUser) {
if (!caseInstance.save(flush:true)) {
if (log.isDebugEnabled()) {
caseInstance.errors.allErrors.each { log.debug it }
}
throw new CaseException(message: "case.cmCase.exception", caseInstance: caseInstance)
}
return caseInstance
}
Hibernate 在执行其他查询但不更新时显示所有选择和插入。