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

Conversation

codeconsole
Copy link
Contributor

@codeconsole codeconsole commented Dec 5, 2024

Currently if no layout is specified, none is set. Since there is no concept of a none layout in Sitemesh 3, it attempts to find a layout named none.

Before 7 is final, more time will need to be spent perfecting layout resolution. There is not clear separation of concerns.

The following question needs to be addressed prior to RC1

Should layout resolution be specific to controllers? currently (and prior) this trait is applied to Controllers, RestControllers, and Interceptors. I am not sure if RestControllers or Interceptors should be so tightly coupled to SiteMesh.

Perhaps all this layout logic should be removed and done directly inside Controller.

@codeconsole
Copy link
Contributor Author

Copy link
Contributor

@matrei matrei left a comment

Choose a reason for hiding this comment

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

Excellent! This resolves the render(text: '...') problem and three more test are successful in grails-functional-tests.

I have made some comments that I think will make the code clearer and also make it less coupled with a specific layout engine.

@@ -533,13 +533,12 @@ trait ResponseRenderer extends WebAttributes {
}

private void applySiteMeshLayout(HttpServletRequest request, boolean renderView, String explicitSiteMeshLayout) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename method to setLayout and possibly make static?
Param renderView is unused both before and after this change. Remove?
Rename param explicitSiteMeshLayout to layout?

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?

@matrei
Copy link
Contributor

matrei commented Dec 5, 2024

Also the WebUtils.NONE_LAYOUT is now unused, Delete?

@codeconsole codeconsole merged commit 53baea1 into grails:7.0.x Dec 5, 2024
19 checks passed
matrei added a commit to grails/grails-functional-tests that referenced this pull request Dec 5, 2024
@jeffscottbrown
Copy link
Member

jeffscottbrown commented Dec 5, 2024

Instead of this…

private void setLayout(HttpServletRequest request, String layout) {
    if (layout == null || request.getAttribute(WebUtils.LAYOUT_ATTRIBUTE) != null) {
        // layout has been set already
        return
    }
    request.setAttribute WebUtils.LAYOUT_ATTRIBUTE, layout
}

Could it just be this…

private void setLayout(HttpServletRequest request, String layout) {
    // if layout is provided and the layout attribute hasn’t already been set, set it
    if (layout != null && request.getAttribute(WebUtils.LAYOUT_ATTRIBUTE) == null) {
        request.setAttribute WebUtils.LAYOUT_ATTRIBUTE, layout
    }
}

@codeconsole
Copy link
Contributor Author

codeconsole commented Dec 5, 2024

Instead of this…

true, I was working backwards. I guess I was trying to preserve as much of the original code as possible.

@jeffscottbrown
Copy link
Member

I guess I was trying to preserve as much of the original code as possible.

My suggestion works against that goal. Please ignore.

matrei added a commit to grails/grails-functional-tests that referenced this pull request Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants