- All Superinterfaces:
View
- All Known Implementing Classes:
HelloModelAndView
Another way to use JStachio with Spring MVC is to have models implement Springs
View
interface. You can enforce that your models implement this interface with
JStacheInterfaces
. Alternatively one can call of(Object)
on the model
and return the result.
This view will by default use the static jstachio singleton and if configured correctly that will be the spring version.
This approach has pros and cons. It makes your models slightly coupled to Spring MVC
but allows you to return different views if say you had to redirect on some inputs
(RedirectView
).
- Author:
- agentgt
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default buffer limit before bailing on trying to setContent-Length
.static final MediaType
The default media type is "text/html; charset=UTF-8
".Fields inherited from interface org.springframework.web.servlet.View
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
-
Method Summary
Modifier and TypeMethodDescriptiondefault Output.CloseableEncodedOutput<IOException>
createOutput
(Charset charset, jakarta.servlet.http.HttpServletResponse response) Creates the output from the servlet response to use for rendering.default String
default MediaType
The media type for this view.default JStachio
jstachio()
Returns the jstachio singleton by default.default Object
model()
The model to be rendered byjstachio()
.static JStachioModelView
Creates a spring view from a model with content type: "text/html; charset=UTF-8
".static JStachioModelView
Creates a spring view from a model.static JStachioModelView
Creates a spring view from a model.default void
render
(Map<String, ?> model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
-
Field Details
-
DEFAULT_MEDIA_TYPE
The default media type is "text/html; charset=UTF-8
". -
DEFAULT_BUFFER_LIMIT
The default buffer limit before bailing on trying to setContent-Length
. The default is "65536".- See Also:
-
-
Method Details
-
render
-
createOutput
default Output.CloseableEncodedOutput<IOException> createOutput(Charset charset, jakarta.servlet.http.HttpServletResponse response) Creates the output from the servlet response to use for rendering.- Parameters:
charset
- charset resolved fromgetMediaType()
response
- servlet response- Returns:
- output that should be closed when finished
-
jstachio
Returns the jstachio singleton by default.- Returns:
- stachio singleton by default.
- See Also:
-
model
The model to be rendered byjstachio()
.- Returns:
- model defaulting to
this
instance.
-
getContentType
- Specified by:
getContentType
in interfaceView
-
getMediaType
The media type for this view. The default is "text/html; charset=UTF-8
".- Returns:
- the media type
-
of
Creates a spring view from a model with content type: "text/html; charset=UTF-8
".- Parameters:
model
- an instance of a class annotated withJStache
.- Returns:
- view ready for rendering
-
of
Creates a spring view from a model.- Parameters:
model
- an instance of a class annotated withJStache
.contentType
- SeegetContentType()
- Returns:
- view ready for rendering
-
of
Creates a spring view from a model.- Parameters:
model
- an instance of a class annotated withJStache
.mediaType
- the mediaType- Returns:
- view ready for rendering
-