Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for GRAILS-8605 g.eachError(bean: instanceName) returns error mes…

…sage while used in controllers
  • Loading branch information...
commit 15b2fade2f2910603048dfdcb080b5821067b879 1 parent bb49cb3
@lhotari lhotari authored
View
17 grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/taglib/ValidationTagLibTests.groovy
@@ -260,6 +260,23 @@ enum Title implements org.springframework.context.MessageSourceResolvable {
assertTrue result.contains("releaseDate|")
assertTrue result.contains("publisherURL|")
}
+
+
+ void testEachErrorTagInController() {
+ def b = ga.getDomainClass("ValidationTagLibBook").newInstance()
+ b.validate()
+
+ assertTrue b.hasErrors()
+
+ def g = appCtx.gspTagLibraryLookup.lookupNamespaceDispatcher("g")
+ def errorFields = []
+ g.eachError(bean: b) {
+ errorFields << it.field
+ }
+ assertTrue errorFields.contains("title")
+ assertTrue errorFields.contains("releaseDate")
+ assertTrue errorFields.contains("publisherURL")
+ }
void testRenderErrorsTag() {
def b = ga.getDomainClass("ValidationTagLibBook").newInstance()
View
62 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/taglib/GroovyPageTagBody.java
@@ -91,32 +91,34 @@ private Object captureClosureOutput(Object args, boolean hasArgument) {
Object bodyResult;
- if(hasArgument) {
- originalIt = saveItVariable(currentBinding, args);
- }
-
- if (args instanceof Map && ((Map)args).size() > 0) {
- // The body can be passed a set of variables as a map that
- // are then made available in the binding. This allows the
- // contents of the body to reference any of these variables
- // directly.
- //
- // For example, body(foo: 1, bar: 'test') would allow this
- // GSP fragment to work:
- //
- // <td>Foo: ${foo} and bar: ${bar}</td>
- //
- // Note that any variables with the same name as one of the
- // new ones will be overridden for the scope of the host
- // tag's body.
-
- // GRAILS-2675: Copy the current binding so that we can
- // restore
- // it to its original state.
-
- // Binding is only changed currently when body gets a map
- // argument
- savedVariablesMap = addAndSaveVariables(currentBinding, (Map)args);
+ if(currentBinding != null) {
+ if(hasArgument) {
+ originalIt = saveItVariable(currentBinding, args);
+ }
+
+ if (args instanceof Map && ((Map)args).size() > 0) {
+ // The body can be passed a set of variables as a map that
+ // are then made available in the binding. This allows the
+ // contents of the body to reference any of these variables
+ // directly.
+ //
+ // For example, body(foo: 1, bar: 'test') would allow this
+ // GSP fragment to work:
+ //
+ // <td>Foo: ${foo} and bar: ${bar}</td>
+ //
+ // Note that any variables with the same name as one of the
+ // new ones will be overridden for the scope of the host
+ // tag's body.
+
+ // GRAILS-2675: Copy the current binding so that we can
+ // restore
+ // it to its original state.
+
+ // Binding is only changed currently when body gets a map
+ // argument
+ savedVariablesMap = addAndSaveVariables(currentBinding, (Map)args);
+ }
}
bodyResult = executeClosure(args);
@@ -126,9 +128,11 @@ private Object captureClosureOutput(Object args, boolean hasArgument) {
return capturedOut.getBuffer();
}
finally {
- restoreVariables(currentBinding, savedVariablesMap);
- if (hasArgument) {
- restoreItVariable(currentBinding, originalIt);
+ if(currentBinding != null) {
+ restoreVariables(currentBinding, savedVariablesMap);
+ if (hasArgument) {
+ restoreItVariable(currentBinding, originalIt);
+ }
}
popCapturedOut();
}
Please sign in to comment.
Something went wrong with that request. Please try again.