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

Grails 7.0.0-M1 - Application with layout within a layout throws grails exception #13988

Open
boardbloke opened this issue Jan 28, 2025 · 4 comments

Comments

@boardbloke
Copy link

Expected Behavior

I can embed layouts within layouts

This worked in Grail 6

Actual Behaviour

Get an error:

java.lang.IllegalStateException: Cannot set request attribute - request is not active anymore!
	at org.springframework.web.context.request.ServletRequestAttributes.setAttribute(ServletRequestAttributes.java:177)
	at org.grails.web.taglib.encoder.WebOutputContextLookup$WebOutputContext.setBinding(WebOutputContextLookup.java:114)
	at org.grails.gsp.GroovyPageWritable.doWriteTo(GroovyPageWritable.java:151)
	at org.grails.gsp.GroovyPageWritable.writeTo(GroovyPageWritable.java:82)
	at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:76)
	at org.grails.web.servlet.view.AbstractGrailsView.renderWithinGrailsWebRequest(AbstractGrailsView.java:72)
	at org.grails.web.servlet.view.AbstractGrailsView.renderMergedOutputModel(AbstractGrailsView.java:56)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1435)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1105)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:978)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
	at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
	at org.sitemesh.webapp.WebAppContext.dispatch(WebAppContext.java:205)
	at org.sitemesh.webapp.WebAppContext.decorate(WebAppContext.java:176)
	at org.sitemesh.BaseSiteMeshContext.decorate(BaseSiteMeshContext.java:55)
	at org.sitemesh.webapp.SiteMeshFilter.postProcess(SiteMeshFilter.java:100)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.processInternally(ContentBufferingFilter.java:253)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.bufferAndPostProcess(ContentBufferingFilter.java:239)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.doFilter(ContentBufferingFilter.java:158)
	at org.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:144)
	at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
	at java.base/java.lang.Thread.run(Thread.java:840)

2025-01-28T17:24:16.966Z ERROR 430760 --- [nio-8080-exec-1] .C.[.[.[.[dispatcherServletRegistration] : Servlet.service() for servlet [dispatcherServletRegistration] in context with path [] threw exception

java.io.IOException: Could not dispatch to decorator
	at org.sitemesh.webapp.WebAppContext.decorate(WebAppContext.java:187)
	at org.sitemesh.BaseSiteMeshContext.decorate(BaseSiteMeshContext.java:55)
	at org.sitemesh.webapp.SiteMeshFilter.postProcess(SiteMeshFilter.java:100)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.processInternally(ContentBufferingFilter.java:253)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.bufferAndPostProcess(ContentBufferingFilter.java:239)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.doFilter(ContentBufferingFilter.java:158)
	at org.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:144)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:114)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:483)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:397)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:905)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: jakarta.servlet.ServletException: Request processing failed: org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: Cannot set request attribute - request is not active anymore!
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1022)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
Caused by: jakarta.servlet.ServletException: Request processing failed: org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: Cannot set request attribute - request is not active anymore!

	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:633)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:409)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:331)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:268)
	at org.sitemesh.webapp.WebAppContext.dispatch(WebAppContext.java:205)
	at org.sitemesh.webapp.WebAppContext.decorate(WebAppContext.java:176)
	... 40 common frames omitted
Caused by: org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: Cannot set request attribute - request is not active anymore!
	at org.grails.web.servlet.view.GroovyPageView.createGroovyPageException(GroovyPageView.java:135)
	at org.grails.web.servlet.view.GroovyPageView.handleException(GroovyPageView.java:112)
	at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:80)
	at org.grails.web.servlet.view.AbstractGrailsView.renderWithinGrailsWebRequest(AbstractGrailsView.java:72)
Caused by: org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: Cannot set request attribute - request is not active anymore!

	at org.grails.web.servlet.view.AbstractGrailsView.renderMergedOutputModel(AbstractGrailsView.java:56)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1435)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1105)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:978)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
	... 68 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot set request attribute - request is not active anymore!
	at org.springframework.web.context.request.ServletRequestAttributes.setAttribute(ServletRequestAttributes.java:177)
	at org.grails.web.taglib.encoder.WebOutputContextLookup$WebOutputContext.setBinding(WebOutputContextLookup.java:114)
	at org.grails.gsp.GroovyPageWritable.doWriteTo(GroovyPageWritable.java:151)
	at org.grails.gsp.GroovyPageWritable.writeTo(GroovyPageWritable.java:82)
	at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:76)
	at org.grails.web.servlet.view.AbstractGrailsView.renderWithinGrailsWebRequest(AbstractGrailsView.java:72)
	at org.grails.web.servlet.view.AbstractGrailsView.renderMergedOutputModel(AbstractGrailsView.java:56)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314)
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1435)
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1167)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1105)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:978)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
	at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
	at org.sitemesh.webapp.WebAppContext.dispatch(WebAppContext.java:205)
	at org.sitemesh.webapp.WebAppContext.decorate(WebAppContext.java:176)
	at org.sitemesh.BaseSiteMeshContext.decorate(BaseSiteMeshContext.java:55)
	at org.sitemesh.webapp.SiteMeshFilter.postProcess(SiteMeshFilter.java:100)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.processInternally(ContentBufferingFilter.java:253)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.bufferAndPostProcess(ContentBufferingFilter.java:239)
	at org.sitemesh.webapp.contentfilter.ContentBufferingFilter.doFilter(ContentBufferingFilter.java:158)
	at org.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:144)
	at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
	... 1 common frames omitted

Caused by: java.lang.IllegalStateException: Cannot set request attribute - request is not active anymore!

Steps To Reproduce

  1. Unzip attached application
  2. use gradle to bootRun
  3. visit localhost:8080/test/example

Environment Information

WSL2
Temurin JDK 17.14

example700M1Web_layout.zip

Example Application

No response

Version

7.0.0-M1

@boardbloke
Copy link
Author

This also explains what i what i am doing - https://blog.mrhaki.com/2011/04/grails-goodness-applying-layouts-in.html?m=1

I'm getting an error in Grails 7.0.0-M1

@boardbloke
Copy link
Author

boardbloke commented Jan 28, 2025

Just discovered codeconsole/grails-plugin-sitemesh3#3 which I think is related

Don't seem to be able to apply nested layouts using nested tags though - the outer one is ignored

@jdaugherty
Copy link
Contributor

@codeconsole can you think of other workarounds?

@boardbloke
Copy link
Author

boardbloke commented Jan 29, 2025

Hi in case it's of use to anybody else - I have managed to engineer a workaround for by leveraging the Site Mesh class MetaTagBasedDecoratorSelector which has support for chaining layouts if you specify them comma separated.

So, e.g, rather than having page1.gsp have a meta tag <meta name="layout" content="layoutBock"/> ,
and then having a layoutBock.gsp page that has <g:applyLayout name="main"> tag

Instead I have a meta tag in page1.gsp thus:

<meta name="layout" content="layoutBlock,main"/>

and I removed the g:applyLayout tag in layoutBlock.gsp.

That appears to facilitate template chaining. I.e. having a layout use a layout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants