Permalink
Browse files

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

  • Loading branch information...
lhotari committed May 21, 2012
1 parent b0ccb7b commit d94bf25703e5db5c140fef675549a6bcbea36ef7
@@ -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);
}
@@ -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));
@@ -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();

0 comments on commit d94bf25

Please sign in to comment.