Permalink
Browse files

GRAILS-4655 add clearErrors() method to command objects

  • Loading branch information...
1 parent 3c2d214 commit 6d9e3e50c2f8f6221f4bef48112cda86f9d42161 @jeffbrown jeffbrown committed Jun 6, 2009
@@ -50,6 +50,7 @@ import org.codehaus.groovy.grails.web.metaclass.WithFormMethod
import org.codehaus.groovy.grails.web.metaclass.ForwardMethod
import org.springframework.beans.BeanUtils
import org.codehaus.groovy.grails.plugins.DomainClassPluginSupport
+import org.springframework.validation.BeanPropertyBindingResult
/**
* A plug-in that handles the configuration of controllers for Grails
@@ -311,6 +312,9 @@ class ControllersGrailsPlugin {
} else {
commandObjectMetaClass.constraints = [:]
}
+ commandObjectMetaClass.clearErrors = {->
+ delegate.setErrors (new BeanPropertyBindingResult(delegate, delegate.getClass().getName()))
+ }
}
}
@@ -1,7 +1,7 @@
/**
* @author Graeme Rocher
* @since 1.0
- *
+ *
* Created: Nov 28, 2007
*/
package org.codehaus.groovy.grails.web.servlet.mvc
@@ -22,6 +22,10 @@ class TestController {
[formErrors:form.errors]
}
+ def three = { Form form ->
+ [form:form]
+ }
+
def validate = { Form form ->
[formErrors:form.validate()]
@@ -38,6 +42,20 @@ class Form {
'''
}
+ void testClearErrors() {
+ def controller = ga.getControllerClass("TestController").newInstance()
+
+ controller.params.url = "not_a_url"
+ controller.params.input = "helloworld"
+
+ def model = controller.three()
+
+ def form = model.form
+ assertNotNull 'did not find expected form', form
+ assertTrue 'form should have had errors', form.hasErrors()
+ form.clearErrors()
+ assertFalse 'clearErrors did not work', form.hasErrors()
+ }
void testHasErrors() {
def controller = ga.getControllerClass("TestController").newInstance()

0 comments on commit 6d9e3e5

Please sign in to comment.