Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix GRAILS-8570 g:set not always setting variable in g:include

  • Loading branch information...
commit 9d2fabb22e2f110f34676a3458ae9813c65f1ad5 1 parent e9084ff
@lhotari lhotari authored
View
11 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/pages/GroovyPageBinding.java
@@ -151,7 +151,7 @@ private void internalSetVariable(Binding bindingToUse, String name, Object value
if (!GroovyPage.isReservedName(name)) {
if (bindingToUse == null) {
bindingToUse = findBindingForVariable(name);
- if (bindingToUse == null || (bindingToUse instanceof GroovyPageBinding && ((GroovyPageBinding)bindingToUse).isRoot())) {
+ if (bindingToUse == null || (bindingToUse instanceof GroovyPageBinding && ((GroovyPageBinding)bindingToUse).shouldUseChildBinding(this))) {
bindingToUse = this;
}
}
@@ -172,6 +172,15 @@ private void internalSetVariable(Binding bindingToUse, String name, Object value
}
}
+ private boolean shouldUseChildBinding(GroovyPageBinding childBinding) {
+ return isRoot() || hasSameOwnerClass(childBinding);
+ }
+
+ private boolean hasSameOwnerClass(GroovyPageBinding otherBinding) {
+ // owner class can be same in recursive rendering; in that case, the child binding should be used for setting variable values
+ return (getOwner() != null && otherBinding.getOwner() != null && getOwner().getClass()==otherBinding.getOwner().getClass());
+ }
+
public String getPluginContextPath() {
return (String)getVariable(GroovyPage.PLUGIN_CONTEXT_PATH);
}
View
5 grails-web/src/main/groovy/org/codehaus/groovy/grails/web/pages/GroovyPageWritable.java
@@ -135,10 +135,7 @@ public Writer writeTo(Writer out) throws IOException {
boolean newParentCreated = false;
if (hasRequest) {
- boolean isIncludeRequest = WebUtils.isIncludeRequest(request);
- if(!isIncludeRequest) {
- parentBinding = (GroovyPageBinding) request.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE);
- }
+ parentBinding = (GroovyPageBinding) request.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE);
if (parentBinding == null) {
if (webRequest != null) {
parentBinding = new GroovyPageBinding(new GroovyPageRequestBinding(webRequest));
View
1  grails-web/src/main/groovy/org/codehaus/groovy/grails/web/util/WebUtils.java
@@ -337,6 +337,7 @@ public static IncludedContent includeForUrlMappingInfo(HttpServletRequest reques
Map currentParams = null;
if (webRequest != null) {
currentPageBinding = (Binding) webRequest.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE, 0);
+ webRequest.removeAttribute(GrailsApplicationAttributes.PAGE_SCOPE, 0);
currentController = webRequest.getControllerName();
currentAction = webRequest.getActionName();
currentId = webRequest.getId();
Please sign in to comment.
Something went wrong with that request. Please try again.