Top Description Fields Constructors Methods
org.springframework.web.servlet.view

public abstract Class AbstractTemplateView

extends AbstractUrlBasedView
Class Inheritance
Known Direct Subclasses
org.springframework.web.servlet.view.freemarker.FreeMarkerView, org.springframework.web.servlet.view.groovy.GroovyMarkupView
Imports
java.util.Enumeration, .LinkedHashMap, .Map, jakarta.servlet.ServletException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, .HttpSession, org.springframework.web.servlet.support.RequestContext

Adapter base class for template-based view technologies such as FreeMarker, with the ability to use request and session attributes in their model and the option to expose helper objects for Spring's FreeMarker macro library.

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.

Authors
Juergen Hoeller, Darren Davison
Since
1.0.2
See Also
AbstractTemplateViewResolver, org.springframework.web.servlet.view.freemarker.FreeMarkerView

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private boolean
private boolean
private boolean
public static final String
SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE

Variable name of the RequestContext instance in the template model, available to Spring's macros: e.g. for creating BindStatus objects.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
applyContentType(HttpServletResponse
current HTTP response
response
)

Apply this view's content type as specified in the "contentType" bean property to the given response.

protected final void
renderMergedOutputModel(Map<String, Object>
combined output Map (never null), with dynamic values taking precedence over static attributes
model
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
)

Implements abstract org.springframework.web.servlet.view.AbstractView.renderMergedOutputModel.

Subclasses must implement this method to actually render the view.

protected abstract void
renderMergedTemplateModel(Map<String, Object>
combined output Map, with request attributes and session attributes merged into it if required
model
,
HttpServletRequest
current HTTP request
request
,
HttpServletResponse
current HTTP response
response
)

Subclasses must implement this method to actually render the view.

public void
setAllowRequestOverride(boolean allowRequestOverride)

Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.

public void
setAllowSessionOverride(boolean allowSessionOverride)

Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.

public void
setExposeRequestAttributes(boolean exposeRequestAttributes)

Set whether all request attributes should be added to the model prior to merging with the template.

public void
setExposeSessionAttributes(boolean exposeSessionAttributes)

Set whether all HttpSession attributes should be added to the model prior to merging with the template.

public void
setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers)

Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".

Inherited from org.springframework.web.servlet.view.AbstractUrlBasedView:
afterPropertiesSetcheckResourcegetUrlisUrlRequiredsetUrltoString

Field Detail

allowRequestOverrideback to summary
private boolean allowRequestOverride
allowSessionOverrideback to summary
private boolean allowSessionOverride
exposeRequestAttributesback to summary
private boolean exposeRequestAttributes
exposeSessionAttributesback to summary
private boolean exposeSessionAttributes
exposeSpringMacroHelpersback to summary
private boolean exposeSpringMacroHelpers
SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTEback to summary
public static final String SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE

Variable name of the RequestContext instance in the template model, available to Spring's macros: e.g. for creating BindStatus objects.

Constructor Detail

AbstractTemplateViewback to summary
public AbstractTemplateView()

Method Detail

applyContentTypeback to summary
protected void applyContentType(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:HttpServletResponse

current HTTP response

See Also
setContentType
renderMergedOutputModelback to summary
protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception

Implements abstract org.springframework.web.servlet.view.AbstractView.renderMergedOutputModel.

Doc from org.springframework.web.servlet.view.AbstractView.renderMergedOutputModel.

Subclasses 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.

Parameters
model:Map<String, Object>

combined output Map (never null), with dynamic values taking precedence over static attributes

request:HttpServletRequest

current HTTP request

response:HttpServletResponse

current HTTP response

Annotations
@Override
Exceptions
Exception:
if rendering failed
renderMergedTemplateModelback to summary
protected abstract void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception

Subclasses must implement this method to actually render the view.

Parameters
model:Map<String, Object>

combined output Map, with request attributes and session attributes merged into it if required

request:HttpServletRequest

current HTTP request

response:HttpServletResponse

current HTTP response

Exceptions
Exception:
if rendering failed
setAllowRequestOverrideback to summary
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.

setAllowSessionOverrideback to summary
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.

setExposeRequestAttributesback to summary
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, e.g. FreeMarker, without exposure in the MVC model.

setExposeSessionAttributesback to summary
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".

setExposeSpringMacroHelpersback to summary
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
SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE