Skip to content

Commit 9d2fabb

Browse files
committed
Fix GRAILS-8570 g:set not always setting variable in g:include
1 parent e9084ff commit 9d2fabb

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

grails-web/src/main/groovy/org/codehaus/groovy/grails/web/pages/GroovyPageBinding.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void internalSetVariable(Binding bindingToUse, String name, Object value
151151
if (!GroovyPage.isReservedName(name)) {
152152
if (bindingToUse == null) {
153153
bindingToUse = findBindingForVariable(name);
154-
if (bindingToUse == null || (bindingToUse instanceof GroovyPageBinding && ((GroovyPageBinding)bindingToUse).isRoot())) {
154+
if (bindingToUse == null || (bindingToUse instanceof GroovyPageBinding && ((GroovyPageBinding)bindingToUse).shouldUseChildBinding(this))) {
155155
bindingToUse = this;
156156
}
157157
}
@@ -172,6 +172,15 @@ private void internalSetVariable(Binding bindingToUse, String name, Object value
172172
}
173173
}
174174

175+
private boolean shouldUseChildBinding(GroovyPageBinding childBinding) {
176+
return isRoot() || hasSameOwnerClass(childBinding);
177+
}
178+
179+
private boolean hasSameOwnerClass(GroovyPageBinding otherBinding) {
180+
// owner class can be same in recursive rendering; in that case, the child binding should be used for setting variable values
181+
return (getOwner() != null && otherBinding.getOwner() != null && getOwner().getClass()==otherBinding.getOwner().getClass());
182+
}
183+
175184
public String getPluginContextPath() {
176185
return (String)getVariable(GroovyPage.PLUGIN_CONTEXT_PATH);
177186
}

grails-web/src/main/groovy/org/codehaus/groovy/grails/web/pages/GroovyPageWritable.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ public Writer writeTo(Writer out) throws IOException {
135135
boolean newParentCreated = false;
136136

137137
if (hasRequest) {
138-
boolean isIncludeRequest = WebUtils.isIncludeRequest(request);
139-
if(!isIncludeRequest) {
140-
parentBinding = (GroovyPageBinding) request.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE);
141-
}
138+
parentBinding = (GroovyPageBinding) request.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE);
142139
if (parentBinding == null) {
143140
if (webRequest != null) {
144141
parentBinding = new GroovyPageBinding(new GroovyPageRequestBinding(webRequest));

grails-web/src/main/groovy/org/codehaus/groovy/grails/web/util/WebUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ public static IncludedContent includeForUrlMappingInfo(HttpServletRequest reques
337337
Map currentParams = null;
338338
if (webRequest != null) {
339339
currentPageBinding = (Binding) webRequest.getAttribute(GrailsApplicationAttributes.PAGE_SCOPE, 0);
340+
webRequest.removeAttribute(GrailsApplicationAttributes.PAGE_SCOPE, 0);
340341
currentController = webRequest.getControllerName();
341342
currentAction = webRequest.getActionName();
342343
currentId = webRequest.getId();

0 commit comments

Comments
 (0)