【发布时间】:2012-03-06 21:16:52
【问题描述】:
我在 Grails 应用程序中使用 Java 实体类作为域对象。这些类具有 JSR 303 验证注释(@Size、@NotEmpty 等)。
Grails 控制器和视图在这些实体类中工作得很好,但是当我尝试保存一个约束被破坏的实例(@NotEmpty 字段为空值)时,我收到一个错误页面,其中包含以下内容:
/webcall-account-manager-2/company/save
Class
javax.validation.ConstraintViolationException
Message
Validation failed for classes [com.rcslabs.webcall.server.model.Company] during persist time for groups [javax.validation.groups.Default, ] List of constraint violations:[ ConstraintViolationImpl{interpolatedMessage='may not be empty', propertyPath=name, rootBeanClass=class com.rcslabs.webcall.server.model.Company, messageTemplate='{org.hibernate.validator.constraints.NotBlank.message}'} ]
Around line 27 of grails-app/controllers/com/rcslabs/webcall/server/model/CompanyController.groovy
24: def save() {
25: def companyInstance = new Company()
26: companyInstance.properties = params
27: if (!companyInstance.save(flush: true)) {
28: render(view: "create", model: [companyInstance: companyInstance])
29: return
30: }
Trace
Line | Method
->> 251 | call in org.grails.datastore.gorm.InstanceMethodInvokingClosure
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 27 | save in CompanyController.groovy
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 679 | run . . . in java.lang.Thread
如何以适当的方式处理它(字段上方的消息框)?
【问题讨论】:
标签: java grails bean-validation