Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set layout if none is specified #13908

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename all occurrences in this file of variable name explicitSiteMeshLayout outside of applySiteMeshLayout() to layoutArg?

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
Loading