|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.AbstractView
Abstract View superclass. Standard framework View implementations and application-specific custom Views can extend this class to simplify their implementation. Subclasses should be JavaBeans.
Extends WebApplicationObjectSupport, which will be helpful to some views. Handles static attributes, and merging static with dynamic attributes. Subclasses just need to implement the actual rendering.
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
Field Summary | |
static java.lang.String |
DEFAULT_CONTENT_TYPE
Default content type. |
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport |
logger |
Constructor Summary | |
AbstractView()
|
Method Summary | |
void |
addStaticAttribute(java.lang.String name,
java.lang.Object value)
Add static data to this view, exposed in each view. |
protected RequestContext |
createRequestContext(javax.servlet.http.HttpServletRequest request,
java.util.Map model)
Create a RequestContext to expose under the specified attribute name. |
java.util.Map |
getAttributesMap()
Allow Map access to the static attributes of this view, with the option to add or override specific entries. |
java.lang.String |
getBeanName()
Return the view's name. |
java.lang.String |
getContentType()
Return the content type for this view. |
java.lang.String |
getRequestContextAttribute()
Return the name of the RequestContext attribute, if any. |
java.util.Map |
getStaticAttributes()
Return the static attributes held in this view. |
void |
render(java.util.Map model,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Prepares the view given the specified model, merging it with static attributes and a RequestContext attribute, if necessary. |
protected abstract void |
renderMergedOutputModel(java.util.Map model,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Subclasses must implement this method to actually render the view. |
void |
setAttributes(java.util.Properties props)
Set static attributes from a java.util.Properties object. |
void |
setAttributesCSV(java.lang.String propString)
Set static attributes as a CSV string. |
void |
setAttributesMap(java.util.Map attributes)
Set static attributes from a Map. |
void |
setBeanName(java.lang.String beanName)
Set the view's name. |
void |
setContentType(java.lang.String contentType)
Set the content type for this view. |
void |
setRequestContextAttribute(java.lang.String requestContextAttribute)
Set the name of the RequestContext attribute for this view. |
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport |
getServletContext, getTempDir, getWebApplicationContext |
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, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_CONTENT_TYPE
Constructor Detail |
public AbstractView()
Method Detail |
public void setBeanName(java.lang.String beanName)
setBeanName
in interface BeanNameAware
beanName
- the view's name. May not be null.
Views should use this for log messages.public java.lang.String getBeanName()
public void setContentType(java.lang.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 java.lang.String getContentType()
public void setRequestContextAttribute(java.lang.String requestContextAttribute)
public java.lang.String getRequestContextAttribute()
public void setAttributesCSV(java.lang.String propString) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public void setAttributes(java.util.Properties props)
Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions.
PropertiesEditor
public void setAttributesMap(java.util.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 java.util.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(java.lang.String name, java.lang.Object value)
Must be invoked before any calls to render().
name
- name of attribute to exposevalue
- object to exposepublic java.util.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(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.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
java.lang.Exception
- if rendering failedrenderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected RequestContext createRequestContext(javax.servlet.http.HttpServletRequest request, java.util.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, with dynamic values taking precedence
over static attributes
setRequestContextAttribute(java.lang.String)
,
RequestContext
protected abstract void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.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, with dynamic values taking precedence
over static attributesrequest
- current HTTP requestresponse
- current HTTP response
java.lang.Exception
- if rendering failed
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |