com.interface21.web.servlet
Interface View

All Known Implementing Classes:
AbstractView

public interface View

MVC View for a web interaction. Implementations are responsible for rendering content, and exposing models. Multiple models can be exposed by a single view.
* This class and the MVC approach associated with it is discussed in Chapter 12 of Expert One-On-One J2EE Design and Development by Rod Johnson (Wrox, 2002).
View implementations should be threadsafe.

View implementations may differ widely. An obvious implementation would be JSP based. Other implementations might be XSLT based, or use an HTML generation library. This interface is designed to avoid restricting the range of possible implementations.

Views should be beans. They are likely to be instantiated as beans by a ViewResolver.
This interface is stateless.

Author:
Rod Johnson

Method Summary
 void addStaticAttribute(java.lang.String name, java.lang.Object o)
          Add static data to this view, exposed in each view.
 java.lang.String getName()
          Return the view's name.
 void render(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Renders the view given the specified model.
 void setName(java.lang.String name)
          Set the view's name.
 

Method Detail

addStaticAttribute

public 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().
Note that it is legal for dynamic and static attributes to be supplied with the same name; however, the dynamic attribute will always take precedence, as it was supplied later. This technique is commonly used with titles.
Parameters:
name - name of attribute to expose
o - object to expose

render

public void render(java.util.Map model,
                   javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException,
                   javax.servlet.ServletException
Renders the view given the specified model. The first step will be preparing the request: this commonly consists of setting models as request attributes.
Parameters:
model - HashMap of models (model name String mapped to model object)
request - HttpServletRequest request
response - HttpServletResponse we are building
Throws:
java.io.IOException - if there is an error outputing the data
javax.servlet.ServletException - if there is an unexpected error not related to IO.

setName

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

getName

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


Rod Johnson and Spring contributors 2001-2003.