Skip to content

Commit

Permalink
Merge pull request #13908 from codeconsole/none-layout
Browse files Browse the repository at this point in the history
Don't set layout if none is specified
  • Loading branch information
codeconsole authored Dec 5, 2024
2 parents cc5d4ca + b156f49 commit 53baea1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ trait ResponseRenderer extends WebAttributes {
void render(Map argMap, @DelegatesTo(strategy = Closure.DELEGATE_FIRST) Closure closure) {
GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes()
HttpServletResponse response = webRequest.currentResponse
String explicitSiteMeshLayout = argMap[ARGUMENT_LAYOUT]?.toString() ?: null
String layoutArg = argMap[ARGUMENT_LAYOUT]?.toString() ?: null

applyContentType response, argMap, closure
handleStatusArgument argMap, webRequest, response
Expand All @@ -139,7 +139,7 @@ trait ResponseRenderer extends WebAttributes {
else {
renderMarkupInternal webRequest, closure, response
}
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
setLayout webRequest.currentRequest, layoutArg
}

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

applyContentType response, argMap, body
handleStatusArgument argMap, webRequest, response
render body
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
setLayout webRequest.currentRequest, layoutArg
}

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

handleStatusArgument argMap, webRequest, response
applyContentType response, argMap, writable
renderWritable writable, response
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
setLayout webRequest.currentRequest, layoutArg
webRequest.renderView = false
}

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


Expand All @@ -235,7 +235,7 @@ trait ResponseRenderer extends WebAttributes {
CharSequence text = (textArg instanceof CharSequence) ? ((CharSequence)textArg) : textArg.toString()
render text
}
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
setLayout webRequest.currentRequest, layoutArg
}
else if (argMap.containsKey(ARGUMENT_VIEW)) {
String viewName = argMap[ARGUMENT_VIEW].toString()
Expand Down Expand Up @@ -263,7 +263,7 @@ trait ResponseRenderer extends WebAttributes {
}

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


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

if (renderWithLayout) {
applySiteMeshLayout webRequest.currentRequest, false, explicitSiteMeshLayout
setLayout webRequest.currentRequest, layoutArg
}


Expand Down Expand Up @@ -532,15 +532,12 @@ trait ResponseRenderer extends WebAttributes {
renderArgument instanceof GPathResult ? APPLICATION_XML : defaultEncoding
}

private void applySiteMeshLayout(HttpServletRequest request, boolean renderView, String explicitSiteMeshLayout) {
if(explicitSiteMeshLayout == null && request.getAttribute(WebUtils.LAYOUT_ATTRIBUTE) != null) {
private void setLayout(HttpServletRequest request, String layout) {
if (layout == null || request.getAttribute(WebUtils.LAYOUT_ATTRIBUTE) != null) {
// layout has been set already
return
}
String siteMeshLayout = explicitSiteMeshLayout != null ? explicitSiteMeshLayout : (renderView ? null : WebUtils.NONE_LAYOUT)
if(siteMeshLayout != null) {
request.setAttribute WebUtils.LAYOUT_ATTRIBUTE, siteMeshLayout
}
request.setAttribute WebUtils.LAYOUT_ATTRIBUTE, layout
}

private String getContextPath(GrailsWebRequest webRequest, Map argMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
public static final String DISPATCH_ACTION_PARAMETER = "_action_";
public static final String SEND_ALLOW_HEADER_FOR_INVALID_HTTP_METHOD = "grails.http.invalid.method.allow.header";
public static final String LAYOUT_ATTRIBUTE = "org.grails.layout.name";
public static final String NONE_LAYOUT = "_none_";
public static final String RENDERING_VIEW = "org.grails.rendering.view";
public static final String GRAILS_DISPATCH_EXTENSION = ".dispatch";
public static final String GRAILS_SERVLET_PATH = "/grails";
Expand Down

0 comments on commit 53baea1

Please sign in to comment.