org.springframework.web.servlet.view
Class AbstractView

org.springframework.context.support.ApplicationObjectSupport
  |
  +--org.springframework.web.context.support.WebApplicationObjectSupport
        |
        +--org.springframework.web.servlet.view.AbstractView
Direct Known Subclasses:
AbstractUrlBasedView, AbstractExcelView, AbstractPdfView, AbstractXsltView

public abstract class AbstractView
extends WebApplicationObjectSupport
implements BeanNameAware, View

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 ApplicationObjectSupport, which will be helpful to some views. Handles static attributes, and merging static with dynamic attributes. Subclasses just need to implement the actual rendering.

It's recommended that subclasses don't cache anything, in the quest for efficiency. This class offers caching. However, it's possible to disable this class's caching, which is useful during development.

Author:
Rod Johnson, Juergen Hoeller
Version: $Id: AbstractView.java,v 1.7 2004/02/07 00:18:27 jhoeller Exp $
See Also: renderMergedOutputModel(java.util.Map,HttpServletRequest,HttpServletResponse)

Method Summary
 final voidaddStaticAttribute(String name, Object value)
          Add static data to this view, exposed in each view.
 final StringgetBeanName()
          Return the view's name.
 final MapgetStaticAttributes()
          Handy for testing.
 voidrender(Map model, HttpServletRequest request, HttpServletResponse response)
          Prepares the view given the specified model, merging it with static attributes and a RequestContext attribute, if necessary.
 final voidsetAttributes(Properties props)
          Set static attributes from a java.util.Properties object.
 final voidsetAttributesCSV(String propString)
          Set static attributes as a CSV string.
 final voidsetAttributesMap(Map attributes)
          Set static attributes from a Map.
 final voidsetBeanName(String beanName)
          Set the view's name.
 final voidsetContentType(String contentType)
          Set the content type for this view.
 final voidsetRequestContextAttribute(String requestContextAttribute)
          Set the name of the RequestContext attribute for this view, or null if not needed.

Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, setApplicationContext

Method Detail

addStaticAttribute

public final void addStaticAttribute(String name, Object value)
Add static data to this view, exposed in each view.

Must be invoked before any calls to render().

Parameters:
name - name of attribute to expose
value - object to expose

getBeanName

public final String getBeanName()
Return the view's name. Should never be null, if the view was correctly configured.
Returns: the view's name

getStaticAttributes

public final Map getStaticAttributes()
Handy for testing. Return the static attributes held in this view.
Returns: the static attributes in this view

render

public void render(Map model, HttpServletRequest request, HttpServletResponse response)
throws java.lang.Exception
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.
See Also:
renderMergedOutputModel(java.util.Map,HttpServletRequest,HttpServletResponse)

setAttributes

public final void setAttributes(Properties props)
Set static attributes from a 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.

See Also:
PropertiesEditor

setAttributesCSV

public final void setAttributesCSV(String propString)
throws java.lang.IllegalArgumentException
Set static attributes as a CSV string. Format is attname0={value1},attname1={value1}

setAttributesMap

public final void setAttributesMap(Map attributes)
Set static attributes from a Map. This allows to set any kind of attribute values, for example bean references.

Can be populated with a "map" or "props" element in XML bean definitions.

Parameters:
attributes - Map with name Strings as keys and attribute objects as values

setBeanName

public final void setBeanName(String beanName)
Set the view's name. Helpful for traceability. Framework code must call this when constructing views.
Parameters:
beanName - the view's name. May not be null. Views should use this for log messages.

setContentType

public final void setContentType(String contentType)
Set the content type for this view. May be ignored by subclasses if the view itself is assumed to set the content type, e.g. in case of JSPs.
Parameters:
contentType - content type for this view

setRequestContextAttribute

public final void setRequestContextAttribute(String requestContextAttribute)
Set the name of the RequestContext attribute for this view, or null if not needed.
Parameters:
requestContextAttribute - name of the RequestContext attribute

Association Links

to Class java.lang.String

The name by which this View is known

to Class java.lang.String

Default content type. Overridable as bean property.

to Class java.lang.String

Name of request context attribute, or null if not needed

to Class java.util.Map

Map of static attributes, keyed by attribute name (String)