java.lang.Object | ||||||
↳ | org.springframework.context.support.ApplicationObjectSupport | |||||
↳ | org.springframework.web.context.support.WebApplicationObjectSupport | |||||
↳ | org.springframework.web.servlet.view.AbstractView | |||||
↳ | org.springframework.web.servlet.view.AbstractUrlBasedView | |||||
↳ | org.springframework.web.servlet.view.AbstractTemplateView | |||||
↳ | org.springframework.web.servlet.view.freemarker.FreeMarkerView |
View using the FreeMarker template engine.
Exposes the following JavaBean properties:
Depends on a single FreeMarkerConfig
object such as FreeMarkerConfigurer
being accessible in the current web application context, with any bean name.
Alternatively, you can set the FreeMarker Configuration object as bean property.
See setConfiguration(Configuration)
for more details on the impacts of this approach.
Note: Spring's FreeMarker support requires FreeMarker 2.3 or higher.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.view.AbstractTemplateView
| |||||||||||
From class
org.springframework.web.servlet.view.AbstractView
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From interface
org.springframework.web.servlet.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Check that the FreeMarker template used for this view exists and is valid.
| |||||||||||
Set the FreeMarker Configuration to be used by this view.
| |||||||||||
Set the encoding of the FreeMarker template file.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Autodetect a
FreeMarkerConfig object via the ApplicationContext. | |||||||||||
Build a FreeMarker template model for the given model Map.
| |||||||||||
Render the FreeMarker view to the given response, using the given model
map which contains the complete template model to use.
| |||||||||||
Expose helpers unique to each rendering operation.
| |||||||||||
Return the FreeMarker configuration used by this view.
| |||||||||||
Return the encoding for the FreeMarker template.
| |||||||||||
Return the configured FreeMarker ObjectWrapper, or the
ObjectWrapper#DEFAULT_WRAPPER default wrapper if none specified.
| |||||||||||
Retrieve the FreeMarker template for the given locale,
to be rendering by this view.
| |||||||||||
Retrieve the FreeMarker template specified by the given name,
using the encoding specified by the "encoding" bean property.
| |||||||||||
Invoked on startup.
| |||||||||||
Process the FreeMarker template to the servlet response.
| |||||||||||
Process the model map by merging it with the FreeMarker template.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.view.AbstractTemplateView
| |||||||||||
From class
org.springframework.web.servlet.view.AbstractUrlBasedView
| |||||||||||
From class
org.springframework.web.servlet.view.AbstractView
| |||||||||||
From class
org.springframework.web.context.support.WebApplicationObjectSupport
| |||||||||||
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanNameAware
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.context.ApplicationContextAware
| |||||||||||
From interface
org.springframework.web.context.ServletContextAware
| |||||||||||
From interface
org.springframework.web.servlet.View
|
Check that the FreeMarker template used for this view exists and is valid.
Can be overridden to customize the behavior, for example in case of multiple templates to be rendered into a single view.
locale | the desired Locale that we're looking for |
---|
true
if the resource exists (or is assumed to exist);
false
if we know that it does not existException |
---|
Set the FreeMarker Configuration to be used by this view.
If this is not set, the default lookup will occur: a single FreeMarkerConfig
is expected in the current web application context, with any bean name.
Note: using this method will cause a new instance of TaglibFactory
to created for every single FreeMarkerView
instance. This can be quite expensive
in terms of memory and initial CPU usage. In production it is recommended that you use
a FreeMarkerConfig
which exposes a single shared TaglibFactory.
Set the encoding of the FreeMarker template file. Default is determined by the FreeMarker Configuration: "ISO-8859-1" if not specified otherwise.
Specify the encoding in the FreeMarker Configuration rather than per template if all your templates share a common encoding.
Autodetect a FreeMarkerConfig
object via the ApplicationContext.
BeansException | if no Configuration instance could be found |
---|
Build a FreeMarker template model for the given model Map.
The default implementation builds a AllHttpScopesHashModel.
model | the model to use for rendering |
---|---|
request | current HTTP request |
response | current servlet response |
Render the FreeMarker view to the given response, using the given model map which contains the complete template model to use.
The default implementation renders the template specified by the "url"
bean property, retrieved via getTemplate
. It delegates to the
processTemplate
method to merge the template instance with
the given template model.
Adds the standard Freemarker hash models to the model: request parameters, request, session and application (ServletContext), as well as the JSP tag library hash model.
Can be overridden to customize the behavior, for example to render multiple templates into a single view.
model | the model to use for rendering |
---|---|
request | current HTTP request |
response | current servlet response |
IOException | if the template file could not be retrieved |
---|---|
Exception | if rendering failed |
setUrl(String)
getLocale(HttpServletRequest)
getTemplate(java.util.Locale)
processTemplate(Template, SimpleHash, HttpServletResponse)
Expose helpers unique to each rendering operation. This is necessary so that different rendering operations can't overwrite each other's formats etc.
Called by renderMergedTemplateModel
. The default implementation
is empty. This method can be overridden to add custom helpers to the model.
model | The model that will be passed to the template at merge time |
---|---|
request | current HTTP request |
Exception | if there's a fatal error while we're adding information to the context |
---|
Return the FreeMarker configuration used by this view.
Return the configured FreeMarker ObjectWrapper, or the ObjectWrapper#DEFAULT_WRAPPER default wrapper if none specified.
Retrieve the FreeMarker template for the given locale, to be rendering by this view.
By default, the template specified by the "url" bean property will be retrieved.
locale | the current locale |
---|
IOException | if the template file could not be retrieved |
---|
Retrieve the FreeMarker template specified by the given name, using the encoding specified by the "encoding" bean property.
Can be called by subclasses to retrieve a specific template, for example to render multiple templates into a single view.
name | the file name of the desired template |
---|---|
locale | the current locale |
IOException | if the template file could not be retrieved |
---|
Invoked on startup. Looks for a single FreeMarkerConfig bean to find the relevant Configuration for this factory.
Checks that the template for the default Locale can be found: FreeMarker will check non-Locale-specific templates if a locale-specific one is not found.
servletContext | the ServletContext that this application object runs in
(never null )
|
---|
BeansException |
---|
Process the FreeMarker template to the servlet response.
Can be overridden to customize the behavior.
template | the template to process |
---|---|
model | the model for the template |
response | servlet response (use this to get the OutputStream or Writer) |
IOException | if the template file could not be retrieved |
---|---|
if thrown by FreeMarker | |
TemplateException |
Process the model map by merging it with the FreeMarker template. Output is directed to the servlet response.
This method can be overridden if custom behavior is needed.
model | combined output Map, with request attributes and session attributes merged into it if required |
---|---|
request | current HTTP request |
response | current HTTP response |
Exception |
---|