Class FreeMarkerViewResolver
- All Implemented Interfaces:
Aware
,ApplicationContextAware
,Ordered
,ServletContextAware
,ViewResolver
UrlBasedViewResolver
that supports FreeMarkerView
(i.e. FreeMarker templates) and custom subclasses of it.
The view class for all views generated by this resolver can be specified
via the "viewClass" property. See UrlBasedViewResolver
for details.
Note: To ensure that the correct encoding is used when the rendering
the response, set the content type with an
appropriate charset
attribute — for example,
"text/html;charset=UTF-8"
; however, as of Spring Framework 6.2, it is
no longer strictly necessary to explicitly set the content type in the
FreeMarkerViewResolver
if you have set an explicit encoding via either
FreeMarkerView.setEncoding(String)
,
FreeMarkerConfigurationFactory.setDefaultEncoding(String)
, or
Configuration.setDefaultEncoding(String)
.
Note: When chaining ViewResolvers, a FreeMarkerViewResolver
will
check for the existence of the specified template resources and only return
a non-null View
object if the template was actually found.
Note: Spring's FreeMarker support requires FreeMarker 2.3.33 or higher.
- Since:
- 1.1
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
-
UrlBasedViewResolver.setViewClass(java.lang.Class<?>)
UrlBasedViewResolver.setPrefix(java.lang.String)
UrlBasedViewResolver.setSuffix(java.lang.String)
UrlBasedViewResolver.setContentType(java.lang.String)
UrlBasedViewResolver.setRequestContextAttribute(java.lang.String)
AbstractTemplateViewResolver.setExposeSpringMacroHelpers(boolean)
FreeMarkerView
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
AbstractCachingViewResolver.CacheFilter
-
Field Summary
Fields inherited from class org.springframework.web.servlet.view.UrlBasedViewResolver
FORWARD_URL_PREFIX, REDIRECT_URL_PREFIX
Fields inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
DEFAULT_CACHE_LIMIT
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected AbstractUrlBasedView
Instantiate the specified view class.protected View
Delegates tosuper.loadView(viewName, locale)
for standard behavior and then topostProcessView(FreeMarkerView)
for customization.protected void
postProcessView
(FreeMarkerView freeMarkerView) Post process the suppliedFreeMarkerView
after it has been loaded.protected Class<?>
RequiresFreeMarkerView
.Methods inherited from class org.springframework.web.servlet.view.AbstractTemplateViewResolver
buildView, setAllowRequestOverride, setAllowSessionOverride, setExposeRequestAttributes, setExposeSessionAttributes, setExposeSpringMacroHelpers
Methods inherited from class org.springframework.web.servlet.view.UrlBasedViewResolver
applyLifecycleMethods, canHandle, createView, getAttributesMap, getCacheKey, getContentType, getExposeContextBeansAsAttributes, getExposedContextBeanNames, getExposePathVariables, getOrder, getPrefix, getRedirectHosts, getRequestContextAttribute, getSuffix, getViewClass, getViewNames, initApplicationContext, isRedirectContextRelative, isRedirectHttp10Compatible, setAttributes, setAttributesMap, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setOrder, setPrefix, setRedirectContextRelative, setRedirectHosts, setRedirectHttp10Compatible, setRequestContextAttribute, setSuffix, setViewClass, setViewNames
Methods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
clearCache, getCacheFilter, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheFilter, setCacheLimit, setCacheUnresolved
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
-
Constructor Details
-
FreeMarkerViewResolver
public FreeMarkerViewResolver() -
FreeMarkerViewResolver
- Parameters:
prefix
- the prefix that gets prepended to view names when building a URLsuffix
- the suffix that gets appended to view names when building a URL- Since:
- 4.3
-
-
Method Details
-
requiredViewClass
RequiresFreeMarkerView
.- Overrides:
requiredViewClass
in classAbstractTemplateViewResolver
- See Also:
-
instantiateView
Description copied from class:UrlBasedViewResolver
Instantiate the specified view class.The default implementation uses reflection to instantiate the class.
- Overrides:
instantiateView
in classUrlBasedViewResolver
- Returns:
- a new instance of the view class
- See Also:
-
loadView
Delegates tosuper.loadView(viewName, locale)
for standard behavior and then topostProcessView(FreeMarkerView)
for customization.- Overrides:
loadView
in classUrlBasedViewResolver
- Parameters:
viewName
- the name of the view to retrievelocale
- the Locale to retrieve the view for- Returns:
- the View instance
- Throws:
Exception
- if the view couldn't be resolved- Since:
- 6.2
- See Also:
-
postProcessView
Post process the suppliedFreeMarkerView
after it has been loaded.The default implementation attempts to override the content type of the view with
"text/html;charset=<encoding>"
, where<encoding>
is equal to an explicitly configured character encoding for the underlying FreeMarker template file. If an explicit content type has been configured for this view resolver or if no explicit character encoding has been configured for the template file, this method does not modify the suppliedFreeMarkerView
.
-