Class AbstractTemplateView
- All Implemented Interfaces:
Aware, BeanNameAware, InitializingBean, ApplicationContextAware, ServletContextAware, View
- Direct Known Subclasses:
FreeMarkerView, GroovyMarkupView
JSP/JSTL and other view technologies automatically have access to the HttpServletRequest object and thereby the request/session attributes for the current user. Furthermore, they are able to create and cache helper objects as request attributes themselves.
- Since:
- 1.0.2
- Author:
- Juergen Hoeller, Darren Davison
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringVariable name of the RequestContext instance in the template model, available to Spring's macros: for example, for creating BindStatus objects.Fields inherited from class AbstractView
DEFAULT_CONTENT_TYPEFields inherited from class ApplicationObjectSupport
loggerFields inherited from interface View
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyContentType(jakarta.servlet.http.HttpServletResponse response) Apply this view's content type as specified in the "contentType" bean property to the given response.protected final voidrenderMergedOutputModel(Map<String, Object> model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Subclasses must implement this method to actually render the view.protected abstract voidrenderMergedTemplateModel(Map<String, Object> model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Subclasses must implement this method to actually render the view.voidsetAllowRequestOverride(boolean allowRequestOverride) Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.voidsetAllowSessionOverride(boolean allowSessionOverride) Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.voidsetExposeRequestAttributes(boolean exposeRequestAttributes) Set whether all request attributes should be added to the model prior to merging with the template.voidsetExposeSessionAttributes(boolean exposeSessionAttributes) Set whether all HttpSession attributes should be added to the model prior to merging with the template.voidsetExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".Methods inherited from class AbstractUrlBasedView
afterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toStringMethods inherited from class AbstractView
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponseMethods inherited from class WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
-
Field Details
-
SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE
Variable name of the RequestContext instance in the template model, available to Spring's macros: for example, for creating BindStatus objects.- See Also:
-
-
Constructor Details
-
AbstractTemplateView
public AbstractTemplateView()
-
-
Method Details
-
setExposeRequestAttributes
public void setExposeRequestAttributes(boolean exposeRequestAttributes) Set whether all request attributes should be added to the model prior to merging with the template. Default is "false".Note that some templates may make request attributes visible on their own, for example, FreeMarker, without exposure in the MVC model.
-
setAllowRequestOverride
public void setAllowRequestOverride(boolean allowRequestOverride) Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name. Default is "false" which causes an exception to be thrown if request attributes of the same name as model attributes are found. -
setExposeSessionAttributes
public void setExposeSessionAttributes(boolean exposeSessionAttributes) Set whether all HttpSession attributes should be added to the model prior to merging with the template. Default is "false". -
setAllowSessionOverride
public void setAllowSessionOverride(boolean allowSessionOverride) Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name. Default is "false", which causes an exception to be thrown if session attributes of the same name as model attributes are found. -
setExposeSpringMacroHelpers
public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext". Default is "true".Currently needed for Spring's FreeMarker default macros. Note that this is not required for templates that use HTML forms unless you wish to take advantage of the Spring helper macros.
- See Also:
-
renderMergedOutputModel
protected final void renderMergedOutputModel(Map<String, Object> model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws ExceptionDescription copied from class:AbstractViewSubclasses must implement this method to actually render the view.The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.
- Specified by:
renderMergedOutputModelin classAbstractView- Parameters:
model- combined output Map (nevernull), with dynamic values taking precedence over static attributesrequest- current HTTP requestresponse- current HTTP response- Throws:
Exception- if rendering failed
-
applyContentType
protected void applyContentType(jakarta.servlet.http.HttpServletResponse response) Apply this view's content type as specified in the "contentType" bean property to the given response.Only applies the view's contentType if no content type has been set on the response before. This allows handlers to override the default content type beforehand.
- Parameters:
response- current HTTP response- See Also:
-
renderMergedTemplateModel
protected abstract void renderMergedTemplateModel(Map<String, Object> model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws ExceptionSubclasses must implement this method to actually render the view.- Parameters:
model- combined output Map, with request attributes and session attributes merged into it if requiredrequest- current HTTP requestresponse- current HTTP response- Throws:
Exception- if rendering failed
-