Interface View
- All Known Implementing Classes:
FreemarkerView,JspView,MustacheView,ThymeleafView
@RestOp-annotated method.
A View carries the information a templating engine needs to render a response: the
template name (relative to a base path supplied by the corresponding mixin), an
attribute map exposed to the template, and an optional response-headers seam for
setting Content-Type, Cache-Control, or other headers on the rendered response.
The interface is deliberately minimal and engine-agnostic. Concrete implementations live in the
per-engine bridge modules (juneau-rest-server-view-jsp, future
juneau-rest-server-view-thymeleaf / -mustache / -freemarker), each
paired with a ResponseProcessor that detects its own View subtype and dispatches
to the underlying templating engine.
End-state usage:
Contract:
getTemplateName()— the template path the engine should render, typically relative to a mixin-configured base path (e.g."hello.jsp"with base path"/WEB-INF/views/"resolves to"/WEB-INF/views/hello.jsp"). Must never benull.getAttributes()— key/value bindings exposed to the template (e.g.${name}in a JSP,th:text="${name}"in a Thymeleaf template). Returns an immutable empty map when no attributes are bound. Must never benull.getResponseHeaders()— optional response-headers map applied by the renderer before forwarding to the engine. Defaults to an empty map so most implementations don't need to override it; engines that want to setContent-TypeorCache-Controlon the rendered response can populate this.
Stability:
This interface is the stable extension point for view modules. New methods will be added as
default-bodied where possible to preserve backward compatibility with downstream view
impls.
See Also:
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptionThe attributes to expose to the template.Optional response headers applied by the renderer before forwarding to the templating engine.The name of the template to render — typically a path relative to the mixin-configured base path.
-
Method Details
-
getTemplateName
The name of the template to render — typically a path relative to the mixin-configured base path.For example,
"hello.jsp"with a JSP mixinbasePath("/WEB-INF/views/")resolves to"/WEB-INF/views/hello.jsp"on the request dispatcher.- Returns:
- The template name. Never
null.
-
getAttributes
The attributes to expose to the template.Each entry is forwarded to the templating engine as a named binding accessible from inside the template (e.g.
${name}in JSP / EL,th:text="${name}"in Thymeleaf).- Returns:
- The attributes map. Never
null; returns an immutable empty map when no attributes are bound.
-
getResponseHeaders
Optional response headers applied by the renderer before forwarding to the templating engine.Typical use cases: setting
Content-Type(e.g."text/html; charset=UTF-8") orCache-Controlon the rendered response. The default implementation returns an empty map so mostViewimpls don't need to override it.- Returns:
- An immutable map of headers to apply. Never
null; defaults to an empty map.
-