3
我在Grails应用程序中使用Java实体类作为域对象。这些类具有JSR 303验证注释(@Size,@NotEmpty等)。Grails:如何处理JSR 303 bean验证
的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
怎样才能以正确的方式处理它(字段上方的消息框)?
companyInstance.validate()返回true – weekens 2012-02-16 07:09:21