com.interface21.web.servlet.view
Class AbstractView

java.lang.Object
  |
  +--com.interface21.context.support.ApplicationObjectSupport
        |
        +--com.interface21.web.servlet.view.AbstractView
All Implemented Interfaces:
ApplicationContextAware, View
Direct Known Subclasses:
AbstractExcelView, AbstractPdfView, AbstractXsltView, InternalResourceView, RedirectView, VelocityView

public abstract class AbstractView
extends ApplicationObjectSupport
implements 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.

Version:
$Id: AbstractView.java,v 1.6 2003/06/20 20:28:44 jhoeller Exp $
Author:
Rod Johnson
See Also:
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

Fields inherited from class com.interface21.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
AbstractView()
           
 
Method Summary
 void addStaticAttribute(java.lang.String name, java.lang.Object o)
          Add static data to this view, exposed in each view.
protected  java.lang.String getContentType()
           
 java.lang.String getName()
          Return the view's name.
 java.util.Map getStaticAttributes()
          Handy for testing.
 void render(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Prepares the view given the specified model.
protected abstract  void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Subclasses must implement this method to render the view.
 void setAttributes(java.util.Properties prop)
          Set static attributes from a java.util.Properties object.
 void setAttributesCSV(java.lang.String propString)
          Set static attributes as a CSV string.
 void setContentType(java.lang.String contentType)
          Set the content type for this view.
 void setName(java.lang.String name)
          Set the view's name.
 void setRequestContextAttribute(java.lang.String requestContextAttribute)
          Set the name of the RequestContext attribute for all views, or null if not needed.
 
Methods inherited from class com.interface21.context.support.ApplicationObjectSupport
getApplicationContext, initApplicationContext, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractView

public AbstractView()
Method Detail

setAttributesCSV

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

setAttributes

public final void setAttributes(java.util.Properties prop)
                         throws java.lang.IllegalArgumentException
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.

Relies on registration of PropertiesEditor.

See Also:
PropertiesEditor

setContentType

public final void setContentType(java.lang.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

getContentType

protected final java.lang.String getContentType()

setRequestContextAttribute

public void setRequestContextAttribute(java.lang.String requestContextAttribute)
Set the name of the RequestContext attribute for all views, or null if not needed.
Parameters:
requestContextAttribute - name of the RequestContext attribute

addStaticAttribute

public final void addStaticAttribute(java.lang.String name,
                                     java.lang.Object o)
Add static data to this view, exposed in each view.
Must be invoked before any calls to render().
Specified by:
addStaticAttribute in interface View
Parameters:
name - name of attribute to expose
o - object to expose

getStaticAttributes

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

setName

public final void setName(java.lang.String name)
Set the view's name. Helpful for traceability. Framework code must call this when constructing views.
Specified by:
setName in interface View
Parameters:
name - the view's name. May not be null. Views should use this for log messages.

getName

public final java.lang.String getName()
Return the view's name. Should never be null, if the view was correctly configured.
Specified by:
getName in interface View
Returns:
the view's name

render

public final void render(java.util.Map model,
                         javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
                  throws javax.servlet.ServletException,
                         java.io.IOException
Prepares the view given the specified model. Delegates to renderMergedOutputModel for the actual rendering.
Specified by:
render in interface View
See Also:
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

renderMergedOutputModel

protected abstract void renderMergedOutputModel(java.util.Map model,
                                                javax.servlet.http.HttpServletRequest request,
                                                javax.servlet.http.HttpServletResponse response)
                                         throws javax.servlet.ServletException,
                                                java.io.IOException
Subclasses must implement this method to render the view.

The first take will be preparing the request: This may include setting the model elements as attributes, e.g. in the case of a JSP view.

Parameters:
model - combined output Map, with dynamic values taking precedence over static attributes
request - current HTTP request
response - current HTTP response
Throws:
java.io.IOException - if there is an IO exception trying to obtain or render the view
javax.servlet.ServletException - if there is any other error


Rod Johnson and Spring contributors 2001-2003.