Skip to content

Commit

Permalink
Fix GRAILS-6314: grails.sitemesh.default.layout is applied to render …
Browse files Browse the repository at this point in the history
…"...some text...."
  • Loading branch information
lhotari committed Nov 19, 2013
1 parent ec2c641 commit b26ad1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Map;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanMap;
Expand Down Expand Up @@ -127,6 +128,9 @@ public Object invoke(Object target, String methodName, Object[] arguments) {

boolean renderView = true;
GroovyObject controller = (GroovyObject) target;

String explicitSiteMeshLayout = null;

final Object renderArgument = arguments[0];
if (renderArgument instanceof Converter<?>) {
renderView = renderConverter((Converter<?>)renderArgument, response);
Expand All @@ -150,7 +154,7 @@ else if (renderArgument instanceof Map) {
Map argMap = (Map) renderArgument;

if (argMap.containsKey(ARGUMENT_LAYOUT)) {
webRequest.getCurrentRequest().setAttribute(GrailsLayoutDecoratorMapper.LAYOUT_ATTRIBUTE, argMap.get(ARGUMENT_LAYOUT));
explicitSiteMeshLayout = String.valueOf(argMap.get(ARGUMENT_LAYOUT));
}

boolean statusSet = false;
Expand Down Expand Up @@ -283,10 +287,22 @@ else if (statusSet) {
throw new MissingMethodException(METHOD_SIGNATURE, target.getClass(), arguments);
}
}
applySiteMeshLayout(webRequest.getCurrentRequest(), renderView, explicitSiteMeshLayout);
webRequest.setRenderView(renderView);
return null;
}

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

private boolean renderConverter(Converter<?> converter, HttpServletResponse response) {
converter.render(response);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public class GrailsLayoutDecoratorMapper extends AbstractDecoratorMapper {
private GroovyPageLayoutFinder groovyPageLayoutFinder;
public static final String LAYOUT_ATTRIBUTE = GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE;
public static final String NONE_LAYOUT = GroovyPageLayoutFinder.NONE_LAYOUT;
public static final String RENDERING_VIEW = GroovyPageLayoutFinder.RENDERING_VIEW_ATTRIBUTE;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
* @since 2.0
*/
public class GroovyPageLayoutFinder {

public static final String LAYOUT_ATTRIBUTE = "org.grails.layout.name";
public static final String NONE_LAYOUT = "_none_";
public static final String RENDERING_VIEW_ATTRIBUTE = "org.grails.rendering.view";
private static final Log LOG = LogFactory.getLog(GrailsLayoutDecoratorMapper.class);
private static final long LAYOUT_CACHE_EXPIRATION_MILLIS = Long.getLong("grails.gsp.reload.interval", 5000);
Expand Down Expand Up @@ -159,7 +159,7 @@ public Decorator getNamedDecorator(HttpServletRequest request, String name) {
}

public Decorator getNamedDecorator(HttpServletRequest request, String name, boolean viewMustExist) {
if (StringUtils.isBlank(name)) {
if (StringUtils.isBlank(name) || NONE_LAYOUT.equals(name)) {
return null;
}

Expand Down

0 comments on commit b26ad1b

Please sign in to comment.