Skip to content

Commit 53baea1

Browse files
authored
Merge pull request #13908 from codeconsole/none-layout
Don't set layout if none is specified
2 parents cc5d4ca + b156f49 commit 53baea1

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ trait ResponseRenderer extends WebAttributes {
127127
void render(Map argMap, @DelegatesTo(strategy = Closure.DELEGATE_FIRST) Closure closure) {
128128
GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes()
129129
HttpServletResponse response = webRequest.currentResponse
130-
String explicitSiteMeshLayout = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
130+
String layoutArg = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
131131

132132
applyContentType response, argMap, closure
133133
handleStatusArgument argMap, webRequest, response
@@ -139,7 +139,7 @@ trait ResponseRenderer extends WebAttributes {
139139
else {
140140
renderMarkupInternal webRequest, closure, response
141141
}
142-
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
142+
setLayout webRequest.currentRequest, layoutArg
143143
}
144144

145145
private void renderJsonInternal(HttpServletResponse response, @DelegatesTo(value = StreamingJsonBuilder.StreamingJsonDelegate.class, strategy = Closure.DELEGATE_FIRST) Closure callable) {
@@ -158,12 +158,12 @@ trait ResponseRenderer extends WebAttributes {
158158
void render(Map argMap, CharSequence body) {
159159
GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes()
160160
HttpServletResponse response = webRequest.currentResponse
161-
String explicitSiteMeshLayout = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
161+
String layoutArg = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
162162

163163
applyContentType response, argMap, body
164164
handleStatusArgument argMap, webRequest, response
165165
render body
166-
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
166+
setLayout webRequest.currentRequest, layoutArg
167167
}
168168

169169
/**
@@ -202,12 +202,12 @@ trait ResponseRenderer extends WebAttributes {
202202
void render(Map argMap, Writable writable) {
203203
GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes()
204204
HttpServletResponse response = webRequest.currentResponse
205-
String explicitSiteMeshLayout = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
205+
String layoutArg = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
206206

207207
handleStatusArgument argMap, webRequest, response
208208
applyContentType response, argMap, writable
209209
renderWritable writable, response
210-
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
210+
setLayout webRequest.currentRequest, layoutArg
211211
webRequest.renderView = false
212212
}
213213

@@ -220,7 +220,7 @@ trait ResponseRenderer extends WebAttributes {
220220
void render(Map argMap) {
221221
GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes()
222222
HttpServletResponse response = webRequest.currentResponse
223-
String explicitSiteMeshLayout = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
223+
String layoutArg = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
224224
boolean statusSet = handleStatusArgument(argMap, webRequest, response)
225225

226226

@@ -235,7 +235,7 @@ trait ResponseRenderer extends WebAttributes {
235235
CharSequence text = (textArg instanceof CharSequence) ? ((CharSequence)textArg) : textArg.toString()
236236
render text
237237
}
238-
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
238+
setLayout webRequest.currentRequest, layoutArg
239239
}
240240
else if (argMap.containsKey(ARGUMENT_VIEW)) {
241241
String viewName = argMap[ARGUMENT_VIEW].toString()
@@ -263,7 +263,7 @@ trait ResponseRenderer extends WebAttributes {
263263
}
264264

265265
((GroovyObject)this).setProperty "modelAndView", new ModelAndView(viewUri, model)
266-
applySiteMeshLayout webRequest.currentRequest, true, explicitSiteMeshLayout
266+
setLayout webRequest.currentRequest, layoutArg
267267
}
268268
else if (argMap.containsKey(ARGUMENT_TEMPLATE)) {
269269
applyContentType response, argMap, null, false
@@ -296,11 +296,11 @@ trait ResponseRenderer extends WebAttributes {
296296
}
297297

298298

299-
boolean renderWithLayout = (explicitSiteMeshLayout || webRequest.getCurrentRequest().getAttribute(WebUtils.LAYOUT_ATTRIBUTE))
299+
boolean renderWithLayout = (layoutArg || webRequest.getCurrentRequest().getAttribute(WebUtils.LAYOUT_ATTRIBUTE))
300300
// if automatic decoration occurred unwrap, since this is a partial
301301

302302
if (renderWithLayout) {
303-
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
303+
setLayout webRequest.currentRequest, layoutArg
304304
}
305305

306306

@@ -532,15 +532,12 @@ trait ResponseRenderer extends WebAttributes {
532532
renderArgument instanceof GPathResult ? APPLICATION_XML : defaultEncoding
533533
}
534534

535-
private void applySiteMeshLayout(HttpServletRequest request, boolean renderView, String explicitSiteMeshLayout) {
536-
if(explicitSiteMeshLayout == null && request.getAttribute(WebUtils.LAYOUT_ATTRIBUTE) != null) {
535+
private void setLayout(HttpServletRequest request, String layout) {
536+
if (layout == null || request.getAttribute(WebUtils.LAYOUT_ATTRIBUTE) != null) {
537537
// layout has been set already
538538
return
539539
}
540-
String siteMeshLayout = explicitSiteMeshLayout != null ? explicitSiteMeshLayout : (renderView ? null : WebUtils.NONE_LAYOUT)
541-
if(siteMeshLayout != null) {
542-
request.setAttribute WebUtils.LAYOUT_ATTRIBUTE, siteMeshLayout
543-
}
540+
request.setAttribute WebUtils.LAYOUT_ATTRIBUTE, layout
544541
}
545542

546543
private String getContextPath(GrailsWebRequest webRequest, Map argMap) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
6161
public static final String DISPATCH_ACTION_PARAMETER = "_action_";
6262
public static final String SEND_ALLOW_HEADER_FOR_INVALID_HTTP_METHOD = "grails.http.invalid.method.allow.header";
6363
public static final String LAYOUT_ATTRIBUTE = "org.grails.layout.name";
64-
public static final String NONE_LAYOUT = "_none_";
6564
public static final String RENDERING_VIEW = "org.grails.rendering.view";
6665
public static final String GRAILS_DISPATCH_EXTENSION = ".dispatch";
6766
public static final String GRAILS_SERVLET_PATH = "/grails";

0 commit comments

Comments
 (0)