ruthst00 commented on code in PR #16516:
URL: https://github.com/apache/grails-core/pull/16516#discussion_r4181558474
##########
grails-controllers/src/main/groovy/grails/artefact/controller/support/ResponseRenderer.groovy:
##########
@@ -138,6 +138,7 @@ trait ResponseRenderer extends WebAttributes {
try {
response.writer.write(object.inspect())
+ response.flushBuffer()
Review Comment:
Agreed. After a second look, the correct fix for #15819 is **not** in
`ResponseRenderer.groovy` at all — it belongs in
`UrlMappingsInfoHandlerAdapter.groovy`.
**Root cause:** `UrlMappingsInfoHandlerAdapter.handle()` only checks
`webRequest.renderView` in the `result == null` branch. The `result instanceof
Map` and `result instanceof ModelAndView` branches return a `ModelAndView`
unconditionally, even when `render()` was called and set `renderView = false`.
If an action calls `render(template:...)` and then returns a non-null value (or
if something sets the `MODEL_AND_VIEW` request attribute), the adapter returns
a `ModelAndView` to Spring's `DispatcherServlet`, which then tries to resolve
the view and throws `Could not resolve view`.
**The fix** — add a `!webRequest.renderView` guard in
`UrlMappingsInfoHandlerAdapter` after the `MODEL_AND_VIEW` attribute check
(which is the intentional `render(view:)` path) but before the `result
instanceof Map` / `result instanceof ModelAndView` / `result == null` branches:
```groovy
def modelAndView =
request.getAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW)
if (modelAndView instanceof ModelAndView) {
return (ModelAndView) modelAndView // render(view:) — always honour
}
// All other render() variants set renderView=false; don't attempt view
resolution
if (!webRequest.renderView) {
return null
}
if (result instanceof Map) { ... return new ModelAndView(...) }
else if (result instanceof ModelAndView) { return result }
else if (result == null) { return new ModelAndView(actionUri) }
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]