我从服务的域验证中遇到消息方法问题。有谁知道如何解决这个问题?以下是服务方法。当我的 Controller 正在调用时:glossaryService.post(params, 'save')
。
@Transactional
class GlossaryService {
// Saving glossary
def post( def params,def currentURI ) {
params.status = params.status ? Status.PUBLISHED.value() : Status.DRAFT.value()
def result = [success: false, message: ""]
def glossary = null
if (params.action == 'save') {
glossary = new Glossary(params)
} else if (params.action == 'update') {
glossary = Glossary.get(params.id)
glossary.name = params?.name
glossary.description = params?.description
glossary.glossaryTerm = params?.glossaryTerm
glossary.status = params?.status
}
if (glossary.validate()) {
result = glossary.save(flush: true, failOnError: true)
}
if (glossary.hasErrors()) {
transactionStatus.setRollbackOnly()
result.errors = glossary.errors
def errors = glossary.errors.allErrors.collect {
message(error: it)
}
respond glossary.errors, view: '/admin/glossary/'+currentURI, model: [
glossary: params
]
return
}
return result
}
}
它提示的错误是:
最佳答案
注入(inject)messageSource
MessageSource messageSource
然后用messageSource.getMessage(...)