Class ThymeleafViewRenderer
java.lang.Object
org.apache.juneau.rest.server.view.thymeleaf.ThymeleafViewRenderer
- All Implemented Interfaces:
ResponseProcessor,ViewRenderer
ResponseProcessor that detects ThymeleafView-typed return values and asks the
configured TemplateEngine to render them directly onto the response writer.
Auto-registered by ThymeleafMixin via
@Rest(responseProcessors=...)
— callers who add the mixin don't need to wire up this class explicitly. Callers who want
to handle ThymeleafView returns without adopting the mixin can add this class to
their own
responseProcessors list.
Behavior:
- Inspect the response content. If the value is not a
ThymeleafView, returnNEXTso the rest of the chain runs. - Read the active
ThymeleafMixinfrom theRestContextbean store to discover theTemplateEngine(lazy default if no engine bean is registered). - Build a Thymeleaf
Contextpopulated with the view's attribute map. - Apply every entry from
ThymeleafView.getResponseHeaders()viares.setHeader(...). - Default
Content-Typetotext/html;charset=UTF-8if the caller did not set one explicitly (Thymeleaf's HTML template mode emits HTML; an explicit caller header wins). - Call
templateEngine.process(view.getTemplateName(), context, res.getWriter())to stream the rendered output. - When no Thymeleaf engine is on the classpath, the
TemplateEngine-typed import here fails to load at first use and surfacesNO_ENGINE_DIAGNOSTICnaming the missing dependency.
See Also:
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefaultContent-Typeapplied when the view does not specify one explicitly.static final StringDiagnostic message emitted when no Thymeleaf engine can be found on the classpath at render-time.Fields inherited from interface org.apache.juneau.rest.server.processor.ResponseProcessor
FINISHED, NEXT, RESTART -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintprocess(RestOpSession opSession) Process this response if possible.
-
Field Details
-
DEFAULT_CONTENT_TYPE
DefaultContent-Typeapplied when the view does not specify one explicitly.- See Also:
-
NO_ENGINE_DIAGNOSTIC
Diagnostic message emitted when no Thymeleaf engine can be found on the classpath at render-time.Public so tests and consumer apps can pattern-match against the message text without depending on internal string literals.
- See Also:
-
-
Constructor Details
-
ThymeleafViewRenderer
public ThymeleafViewRenderer()
-
-
Method Details
-
process
Description copied from interface:ResponseProcessorProcess this response if possible.- Specified by:
processin interfaceResponseProcessor- Parameters:
opSession- The HTTP call.- Returns:
- One of the following codes:
0 - The processor could not handle the request.1 - The processor was able to fully handle the request.2 - The processor was able to partially handle the request by replacing the output. The response processors should start over.
- Throws:
IOException- If low-level exception occurred on output stream.
Results in aHttpServletResponse.SC_INTERNAL_SERVER_ERRORerror.BasicHttpException- If some other exception occurred.
Can be used to provide an appropriate HTTP response code and message.
-