Closed PeterFokkinga closed 2 months ago
The issue is that HtmlJteViewsRenderer
has the annotation @Produces(MediaType.TEXT_HTML)
whereas DefaultViewsRendererLocator.resolveViewsRenderer
searches for a renderer that produces TurboMediaType.TURBO_STREAM
There are two possible solutions:
TurboStreamJteViewsRenderer
class that extends JteViewsRenderer
and has class annotation @Produces(TurboMediaType.TURBO_STREAM)
TurboMediaType.TURBO_STREAM
to the annotation of HtmlJteViewsRenderer
I can confirm that option 1 works. (I created such a class in my own application)
Option 2 would also require that the resolveViewsRenderer
method supports a @Produces
annotation with multiple values as it doesn't at the moment ie replace in DefaultViewsRendererLocator
line 91 and further with
if (annotation == null) {
return true;
} else if (annotation.getValue(String[].class).isPresent()) {
return Arrays.asList(annotation.getValue(String[].class).get())
.contains(contentType);
} else if (annotation.getValue(String.class).isPresent()) {
return annotation.getValue(String.class).get().equals(contentType);
}
return false;
I'm not sure which of the two would be preferable.
Problably, option 2. Would you be willing to contribute a PR @PeterFokkinga ?
Yes, I'll see if I can add a test to verify the fix (I'm new to Spock).
that turned out to be rather easy 😊 test fails on the 5.3.x branch but is successful with the fix in place
Expected Behavior
It should be possible to return a TURBO_STREAM response using JTE.
Actual Behaviour
No output will be generated, no exception is thrown or logged.
Steps To Reproduce
a handler like the own below would not work when "home" refers to a JTE template ie
home.jte
Environment Information
OSX / Java 21
Example Application
No response
Version
4.3.8