|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.servlet.view.AbstractView
public abstract class AbstractView
Abstract base class for 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(java.util.Properties)
,
setAttributesMap(java.util.Map)
,
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
Field Summary | |
---|---|
static String |
DEFAULT_CONTENT_TYPE
Default content type. |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
logger |
Constructor Summary | |
---|---|
AbstractView()
|
Method Summary | |
---|---|
void |
addStaticAttribute(String name,
Object value)
Add static data to this view, exposed in each view. |
protected RequestContext |
createRequestContext(HttpServletRequest request,
Map model)
Create a RequestContext to expose under the specified attribute name. |
Map |
getAttributesMap()
Allow Map access to the static attributes of this view, with the option to add or override specific entries. |
String |
getBeanName()
Return the view's name. |
String |
getContentType()
Return the content type for this view. |
String |
getRequestContextAttribute()
Return the name of the RequestContext attribute, if any. |
Map |
getStaticAttributes()
Return the static attributes for this view. |
void |
render(Map model,
HttpServletRequest request,
HttpServletResponse response)
Prepares the view given the specified model, merging it with static attributes and a RequestContext attribute, if necessary. |
protected abstract void |
renderMergedOutputModel(Map model,
HttpServletRequest request,
HttpServletResponse response)
Subclasses must implement this method to actually render the view. |
void |
setAttributes(Properties attributes)
Set static attributes for this view from a java.util.Properties object. |
void |
setAttributesCSV(String propString)
Set static attributes as a CSV string. |
void |
setAttributesMap(Map attributes)
Set static attributes for this view from a Map. |
void |
setBeanName(String beanName)
Set the view's name. |
void |
setContentType(String contentType)
Set the content type for this view. |
void |
setRequestContextAttribute(String requestContextAttribute)
Set the name of the RequestContext attribute for this view. |
String |
toString()
|
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
---|
getServletContext, getTempDir, getWebApplicationContext, isContextRequired |
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport |
---|
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_CONTENT_TYPE
Constructor Detail |
---|
public AbstractView()
Method Detail |
---|
public void setBeanName(String beanName)
setBeanName
in interface BeanNameAware
beanName
- the view's name. May not be null
.
Views should use this for log messages.public String getBeanName()
null
,
if the view was correctly configured.
public void setContentType(String contentType)
May be ignored by subclasses if the view itself is assumed to set the content type, e.g. in case of JSPs.
contentType
- content type for this viewDEFAULT_CONTENT_TYPE
public String getContentType()
public void setRequestContextAttribute(String requestContextAttribute)
public String getRequestContextAttribute()
public void setAttributesCSV(String propString) throws IllegalArgumentException
IllegalArgumentException
public void setAttributes(Properties attributes)
java.util.Properties
object.
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.
PropertiesEditor
public void setAttributesMap(Map attributes)
Can be populated with a "map" or "props" element in XML bean definitions.
attributes
- Map with name Strings as keys and attribute objects as valuespublic Map getAttributesMap()
Useful for specifying entries directly, for example via "attributesMap[myKey]". This is particularly useful for adding or overriding entries in child view definitions.
public void addStaticAttribute(String name, Object value)
Must be invoked before any calls to render
.
name
- the name of the attribute to exposevalue
- the attribute value to exposerender(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
public Map getStaticAttributes()
Returns an unmodifiable Map, as this is not intended for manipulating the Map but rather just for checking the contents.
public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception
render
in interface View
model
- Map with name Strings as keys and corresponding model
objects as values (Map can also be null
in case of empty model)request
- current HTTP requestresponse
- HTTP response we are building
Exception
- if rendering failedrenderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected RequestContext createRequestContext(HttpServletRequest request, Map model)
Default implementation creates a standard RequestContext instance for the given request and model. Can be overridden in subclasses for custom instances.
request
- current HTTP requestmodel
- combined output Map (never null
),
with dynamic values taking precedence over static attributes
setRequestContextAttribute(java.lang.String)
,
RequestContext
protected abstract void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception
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.
model
- combined output Map (never null
),
with dynamic values taking precedence over static attributesrequest
- current HTTP requestresponse
- current HTTP response
Exception
- if rendering failedpublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |