|
16 | 16 | package org.grails.web.sitemesh; |
17 | 17 |
|
18 | 18 | import grails.util.Environment; |
| 19 | +import grails.util.GrailsNameUtils; |
19 | 20 | import groovy.lang.GroovyObject; |
20 | 21 |
|
21 | 22 | import java.util.Map; |
|
27 | 28 | import org.apache.commons.logging.LogFactory; |
28 | 29 | import grails.util.GrailsClassUtils; |
29 | 30 | import grails.util.GrailsStringUtils; |
| 31 | +import org.grails.core.artefact.ControllerArtefactHandler; |
30 | 32 | import org.grails.io.support.GrailsResourceUtils; |
31 | 33 | import org.codehaus.groovy.grails.web.metaclass.ControllerDynamicMethods; |
| 34 | +import org.grails.web.servlet.mvc.GrailsWebRequest; |
32 | 35 | import org.grails.web.util.GrailsApplicationAttributes; |
33 | 36 | import org.grails.web.servlet.view.AbstractGrailsView; |
34 | 37 | import org.grails.web.servlet.view.GrailsViewResolver; |
@@ -110,33 +113,40 @@ public Decorator findLayout(HttpServletRequest request, Page page) { |
110 | 113 |
|
111 | 114 | if (GrailsStringUtils.isBlank(layoutName)) { |
112 | 115 | GroovyObject controller = (GroovyObject)request.getAttribute(GrailsApplicationAttributes.CONTROLLER); |
113 | | - if (controller != null) { |
114 | | - String controllerName = (String)controller.getProperty(ControllerDynamicMethods.CONTROLLER_NAME_PROPERTY); |
115 | | - String actionUri = (String)controller.getProperty(ControllerDynamicMethods.ACTION_URI_PROPERTY); |
116 | | - |
117 | | - if (LOG.isDebugEnabled()) { |
118 | | - LOG.debug("Found controller in request, location layout for controller [" + controllerName |
119 | | - + "] and action [" + actionUri + "]"); |
| 116 | + if (controller != null ) { |
| 117 | + GrailsWebRequest webRequest = GrailsWebRequest.lookup(request); |
| 118 | + String controllerName = webRequest.getControllerName(); |
| 119 | + if(controllerName == null) { |
| 120 | + controllerName = GrailsNameUtils.getLogicalPropertyName(controller.getClass().getName(), ControllerArtefactHandler.TYPE); |
120 | 121 | } |
| 122 | + String actionUri = webRequest.getAttributes().getControllerActionUri(request); |
121 | 123 |
|
122 | | - LayoutCacheKey cacheKey = null; |
123 | | - boolean cachedIsNull = false; |
| 124 | + if(controllerName != null && actionUri != null) { |
124 | 125 |
|
125 | | - if (cacheEnabled) { |
126 | | - cacheKey = new LayoutCacheKey(controllerName, actionUri); |
127 | | - DecoratorCacheValue cacheValue = layoutDecoratorCache.get(cacheKey); |
128 | | - if (cacheValue != null && (!gspReloadEnabled || !cacheValue.isExpired())) { |
129 | | - d = cacheValue.getDecorator(); |
130 | | - if (d == null) { |
131 | | - cachedIsNull = true; |
132 | | - } |
| 126 | + if (LOG.isDebugEnabled()) { |
| 127 | + LOG.debug("Found controller in request, location layout for controller [" + controllerName |
| 128 | + + "] and action [" + actionUri + "]"); |
133 | 129 | } |
134 | | - } |
135 | 130 |
|
136 | | - if (d == null && !cachedIsNull) { |
137 | | - d = resolveDecorator(request, controller, controllerName, actionUri); |
| 131 | + LayoutCacheKey cacheKey = null; |
| 132 | + boolean cachedIsNull = false; |
| 133 | + |
138 | 134 | if (cacheEnabled) { |
139 | | - layoutDecoratorCache.put(cacheKey, new DecoratorCacheValue(d)); |
| 135 | + cacheKey = new LayoutCacheKey(controllerName, actionUri); |
| 136 | + DecoratorCacheValue cacheValue = layoutDecoratorCache.get(cacheKey); |
| 137 | + if (cacheValue != null && (!gspReloadEnabled || !cacheValue.isExpired())) { |
| 138 | + d = cacheValue.getDecorator(); |
| 139 | + if (d == null) { |
| 140 | + cachedIsNull = true; |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + if (d == null && !cachedIsNull) { |
| 146 | + d = resolveDecorator(request, controller, controllerName, actionUri); |
| 147 | + if (cacheEnabled) { |
| 148 | + layoutDecoratorCache.put(cacheKey, new DecoratorCacheValue(d)); |
| 149 | + } |
140 | 150 | } |
141 | 151 | } |
142 | 152 | } |
|
0 commit comments