Class FreeMarkerViewResolver
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.core.Ordered,org.springframework.web.context.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_PREFIXFields inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
DEFAULT_CACHE_LIMITFields inherited from class org.springframework.context.support.ApplicationObjectSupport
loggerFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected AbstractUrlBasedViewInstantiate the specified view class.protected ViewDelegates tosuper.loadView(viewName, locale)for standard behavior and then topostProcessView(FreeMarkerView)for customization.protected voidpostProcessView(FreeMarkerView freeMarkerView) Post process the suppliedFreeMarkerViewafter it has been loaded.protected Class<?>RequiresFreeMarkerView.Methods inherited from class org.springframework.web.servlet.view.AbstractTemplateViewResolver
buildView, setAllowRequestOverride, setAllowSessionOverride, setExposeRequestAttributes, setExposeSessionAttributes, setExposeSpringMacroHelpersMethods 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, setViewNamesMethods inherited from class org.springframework.web.servlet.view.AbstractCachingViewResolver
clearCache, getCacheFilter, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheFilter, setCacheLimit, setCacheUnresolvedMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods 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:
requiredViewClassin classAbstractTemplateViewResolver- See Also:
-
instantiateView
Description copied from class:UrlBasedViewResolverInstantiate the specified view class.The default implementation uses reflection to instantiate the class.
- Overrides:
instantiateViewin 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:
loadViewin 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 suppliedFreeMarkerViewafter 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.
-