Skip to content

Commit

Permalink
Merge pull request #13626 from codeconsole/7.0.x-sitemesh-decouple-po…
Browse files Browse the repository at this point in the history
…lish

Use existing constant location
  • Loading branch information
codeconsole committed Sep 8, 2024
2 parents b92629e + 5d06f74 commit 0daf7c6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import org.grails.web.servlet.mvc.GrailsWebRequest
import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException
import org.grails.web.servlet.view.CompositeViewResolver
import org.grails.web.servlet.view.GroovyPageView
import org.grails.plugins.web.controllers.ControllersGrailsPlugin
import org.grails.web.util.GrailsApplicationAttributes
import org.grails.web.util.WebUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.http.HttpStatus
Expand Down Expand Up @@ -296,7 +296,7 @@ trait ResponseRenderer extends WebAttributes {
}


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

if (renderWithLayout) {
Expand Down Expand Up @@ -533,13 +533,13 @@ trait ResponseRenderer extends WebAttributes {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator

import jakarta.servlet.DispatcherType
import jakarta.servlet.MultipartConfigElement

Expand All @@ -63,11 +61,6 @@ class ControllersGrailsPlugin extends Plugin {
def observe = ['domainClass']
def dependsOn = [core: version, i18n: version, urlMappings: version]

// Although they are specific to Sitemesh, these properties need
// a new home that is not coupled to any sitemesh dependency
static final String LAYOUT_ATTRIBUTE = "org.grails.layout.name";
static final String NONE_LAYOUT = "_none_";

@Override
Closure doWithSpring(){ { ->
def application = grailsApplication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.grails.web.servlet.mvc

import org.grails.plugins.web.controllers.ControllersGrailsPlugin
import grails.testing.web.controllers.ControllerUnitTest
import org.grails.web.util.WebUtils
import spock.lang.Specification
import grails.artefact.Artefact
import org.grails.buffer.FastStringWriter
Expand All @@ -15,7 +15,7 @@ class RenderDynamicMethodTests extends Specification implements ControllerUnitTe
then:
response.contentType == response.contentType
response.contentAsString == response.contentAsString
request.getAttribute(ControllersGrailsPlugin.LAYOUT_ATTRIBUTE) == "bar"
request.getAttribute(WebUtils.LAYOUT_ATTRIBUTE) == "bar"
}

void testRenderView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ 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 0daf7c6

Please sign in to comment.