org.springframework.web.servlet.View
implementations. Subclasses should be JavaBeans, to allow for
convenient configuration as Spring-managed bean instances.
Provides support for static attributes, to be made available to the view, with a variety of ways to specify them. Static attributes will be merged with the given dynamic attributes (the model that the controller returned) for each render operation.
Extends WebApplicationObjectSupport, which will be helpful to
some views. Subclasses just need to implement the actual rendering.
setAttributes, setAttributesMap, renderMergedOutputModel
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private String | |
| public static final String | DEFAULT_CONTENT_TYPE
Default content type. |
| private boolean | |
| private Set | |
| private boolean | |
| private static final int | OUTPUT_BYTE_ARRAY_INITIAL_SIZE
Initial size for the temporary output byte array (if any). |
| private String | |
| private final Map |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addStaticAttribute(String
the name of the attribute to expose name, Object the attribute value to expose value)Add static data to this view, exposed in each view. |
| protected Map | createMergedOutputModel(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
Creates a combined output Map (never |
| protected RequestContext | Returns: the RequestContext instancecurrent HTTP request request, HttpServletResponse response, Map<String, Object> combined output Map (never model)null),
with dynamic values taking precedence over static attributesCreate a RequestContext to expose under the specified attribute name. |
| protected ByteArrayOutputStream | |
| protected void | exposeModelAsRequestAttributes(Map<String, Object>
a Map of model objects to expose model, HttpServletRequest current HTTP request request)Expose the model objects in the given map as request attributes. |
| protected String | |
| protected boolean | generatesDownloadContent()
Return whether this view generates download content (typically binary content like PDF or Excel files). |
| public Map | getAttributesMap()
Allow |
| public String | |
| public String | getContentType()
Overrides default org. Return the content type for this view. |
| public String | |
| protected HttpServletRequest | Returns: the wrapped request, or the original request if no wrapping is necessarythe original servlet request as provided by the engine originalRequest)Get the request handle to expose to |
| public Map | Returns: the static attributes in this viewReturn the static attributes for this view. |
| public boolean | |
| protected void | prepareResponse(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response)Prepare the given response for rendering. |
| public void | render(Map<String, ?>
a Map with name Strings as keys and corresponding model
objects as values (Map can also be model, HttpServletRequest null in case of empty model)current HTTP request request, HttpServletResponse he HTTP response we are building response)Implements org. Prepares the view given the specified model, merging it with static attributes and a RequestContext attribute, if necessary. |
| protected abstract void | renderMergedOutputModel(Map<String, Object>
combined output Map (never model, HttpServletRequest null),
with dynamic values taking precedence over static attributescurrent HTTP request request, HttpServletResponse current HTTP response response)Subclasses must implement this method to actually render the view. |
| public void | setAttributes(Properties attributes)
Set static attributes for this view from a
|
| public void | |
| public void | setAttributesMap(Map<String, ?>
a Map with name Strings as keys and attribute objects as values attributes)Set static attributes for this view from a Map. |
| public void | setBeanName(String
the name of the bean in the factory.
Note that this name is the actual bean name used in the factory, which may
differ from the originally specified name: in particular for inner bean
names, the actual bean name might have been made unique through appending
"#..." suffixes. Use the beanName)BeanFactoryUtils#originalBeanName(String)
method to extract the original bean name (without suffix), if desired.Implements org. Set the view's name. |
| public void | |
| public void | setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes)
Set whether to make all Spring beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed. |
| public void | setExposedContextBeanNames(String... exposedContextBeanNames)
Specify the names of beans in the context which are supposed to be exposed. |
| public void | setExposePathVariables(boolean
true to expose path variables, and false otherwiseSpecify whether to add path variables to the model or not. |
| public void | setRequestContextAttribute(String requestContextAttribute)
Set the name of the RequestContext attribute for this view. |
| protected void | setResponseContentType(HttpServletRequest request, HttpServletResponse response)
Set the content type of the response to the configured
|
| public String | |
| protected void | writeToResponse(HttpServletResponse
current HTTP response response, ByteArrayOutputStream the temporary OutputStream to write baos)Write the given temporary OutputStream to the HTTP response. |
| beanName | back to summary |
|---|---|
| private String beanName
| |
| contentType | back to summary |
|---|---|
| private String contentType
| |
| DEFAULT_CONTENT_TYPE | back to summary |
|---|---|
| public static final String DEFAULT_CONTENT_TYPE Default content type. Overridable as bean property. | |
| exposeContextBeansAsAttributes | back to summary |
|---|---|
| private boolean exposeContextBeansAsAttributes | |
| exposedContextBeanNames | back to summary |
|---|---|
| private Set<String> exposedContextBeanNames
| |
| exposePathVariables | back to summary |
|---|---|
| private boolean exposePathVariables | |
| OUTPUT_BYTE_ARRAY_INITIAL_SIZE | back to summary |
|---|---|
| private static final int OUTPUT_BYTE_ARRAY_INITIAL_SIZE Initial size for the temporary output byte array (if any). | |
| requestContextAttribute | back to summary |
|---|---|
| private String requestContextAttribute
| |
| staticAttributes | back to summary |
|---|---|
| private final Map<String, Object> staticAttributes | |
| AbstractView | back to summary |
|---|---|
| public AbstractView() | |
| addStaticAttribute | back to summary |
|---|---|
| public void addStaticAttribute(String name, Object value) Add static data to this view, exposed in each view. "Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model. Must be invoked before any calls to | |
| createMergedOutputModel | back to summary |
|---|---|
| protected Map Creates a combined output Map (never | |
| createRequestContext | back to summary |
|---|---|
| protected RequestContext createRequestContext(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) Create a RequestContext to expose under the specified attribute name. The default implementation creates a standard RequestContext instance for the given request and model. Can be overridden in subclasses for custom instances.
| |
| createTemporaryOutputStream | back to summary |
|---|---|
| protected ByteArrayOutputStream createTemporaryOutputStream() Create a temporary OutputStream for this view. This is typically used as IE workaround, for setting the content length header from the temporary stream before actually writing the content to the HTTP response. | |
| exposeModelAsRequestAttributes | back to summary |
|---|---|
| protected void exposeModelAsRequestAttributes(Map<String, Object> model, HttpServletRequest request) throws Exception Expose the model objects in the given map as request attributes.
Names will be taken from the model Map.
This method is suitable for all resources reachable by
| |
| formatViewName | back to summary |
|---|---|
| protected String formatViewName() | |
| generatesDownloadContent | back to summary |
|---|---|
| protected boolean generatesDownloadContent() Return whether this view generates download content (typically binary content like PDF or Excel files). The default implementation returns | |
| getAttributesMap | back to summary |
|---|---|
| public Map Allow Useful for specifying entries directly, for example via
| |
| getBeanName | back to summary |
|---|---|
| public String getBeanName() Return the view's name. Should never be
| |
| getContentType | back to summary |
|---|---|
| public String getContentType() Overrides default org. Return the content type for this view.
| |
| getRequestContextAttribute | back to summary |
|---|---|
| public String getRequestContextAttribute() Return the name of the RequestContext attribute, if any.
| |
| getRequestToExpose | back to summary |
|---|---|
| protected HttpServletRequest getRequestToExpose(HttpServletRequest originalRequest) Get the request handle to expose to The default implementation wraps the original request for exposure of Spring beans as request attributes (if demanded).
| |
| getStaticAttributes | back to summary |
|---|---|
| public Map Return the static attributes for this view. Handy for testing. Returns an unmodifiable Map, as this is not intended for manipulating the Map but rather just for checking the contents. | |
| isExposePathVariables | back to summary |
|---|---|
| public boolean isExposePathVariables() Return whether to add path variables to the model or not. | |
| prepareResponse | back to summary |
|---|---|
| protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) Prepare the given response for rendering. The default implementation applies a workaround for an IE bug when sending download content via HTTPS.
| |
| render | back to summary |
|---|---|
| public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception Implements org. Prepares the view given the specified model, merging it with static attributes and a RequestContext attribute, if necessary. Delegates to renderMergedOutputModel for the actual rendering.
| |
| renderMergedOutputModel | back to summary |
|---|---|
| protected abstract void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception 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.
| |
| setAttributes | back to summary |
|---|---|
| public void setAttributes(Properties attributes) Set static attributes for this view from a
"Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model. This is the most convenient way to set static attributes. Note that static attributes can be overridden by dynamic attributes, if a value with the same name is included in the model. Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions. | |
| setAttributesCSV | back to summary |
|---|---|
| public void setAttributesCSV(String propString) throws IllegalArgumentException Set static attributes as a CSV string. Format is: attname0={value1},attname1={value1} "Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model. | |
| setAttributesMap | back to summary |
|---|---|
| public void setAttributesMap(Map<String, ?> attributes) Set static attributes for this view from a Map. This allows to set any kind of attribute values, for example bean references. "Static" attributes are fixed attributes that are specified in the View instance configuration. "Dynamic" attributes, on the other hand, are values passed in as part of the model. Can be populated with a "map" or "props" element in XML bean definitions. | |
| setBeanName | back to summary |
|---|---|
| public void setBeanName(String beanName) Implements org. Set the view's name. Helpful for traceability. Framework code must call this when constructing views.
| |
| setContentType | back to summary |
|---|---|
| public void setContentType(String contentType) Set the content type for this view. Default is "text/html;charset=ISO-8859-1". May be ignored by subclasses if the view itself is assumed to set the content type, e.g. in case of JSPs. | |
| setExposeContextBeansAsAttributes | back to summary |
|---|---|
| public void setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) Set whether to make all Spring beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed. This will make all such beans accessible in plain Default is "false". Switch this flag on to transparently expose all Spring beans in the request attribute namespace. Note Context beans will override any custom request or session attributes of the same name that have been manually added. However, model attributes (as explicitly exposed to this view) of the same name will always override context beans.
| |
| setExposedContextBeanNames | back to summary |
|---|---|
| public void setExposedContextBeanNames(String... exposedContextBeanNames) Specify the names of beans in the context which are supposed to be exposed. If this is non-null, only the specified beans are eligible for exposure as attributes. If you'd like to expose all Spring beans in the application context, switch
the | |
| setExposePathVariables | back to summary |
|---|---|
| public void setExposePathVariables(boolean exposePathVariables) Specify whether to add path variables to the model or not. Path variables are commonly bound to URI template variables through the Path variables added to the model override static attributes (see By default this flag is set to
| |
| setRequestContextAttribute | back to summary |
|---|---|
| public void setRequestContextAttribute(String requestContextAttribute) Set the name of the RequestContext attribute for this view. Default is none. | |
| setResponseContentType | back to summary |
|---|---|
| protected void setResponseContentType(HttpServletRequest request, HttpServletResponse response) Set the content type of the response to the configured
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| writeToResponse | back to summary |
|---|---|
| protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException Write the given temporary OutputStream to the HTTP response.
| |