View Implementations

The following UML class diagram shows the view implementations discussed in this appendix, and how all are derived from the AbstractView convenience base class. The two classes at the bottom right illustrate how app-specific classes (in this case, classes from our sample app) extend the abstract framework superclasses for XMLC and PDF views:

Java Click To expand

The following framework view implementations are concrete, and can be used without subclassing:

The following two classes are abstract superclasses for app-specific views. The two view technologies concerned require a Java class to be implemented for each view:

The View interface is simple to implement from scratch, but the com.interface21.web.servlet.view.AbstractView superclass provides a convenient superclass for most view implementations, using the Template Method design pattern to conceal the merging of static attributes with model objects supplied by the controller (if a static attribute and a model attribute share the same name, the model attribute will take precedence). Subclasses of AbstractView need to implement the following protected method, which has the same contract as the render ( ) method from the View interface, but works with a merged map of model and static attributes:

 protected abstract void renderMergedOutputModel (
 Map model,
 HttpServletRequest request,
 HttpServletResponse response)
 throws ServletException, IOException;

AbstractView invokes this method in a final implementation of the render() method as follows. Note that dynamic (model) attribute values will replace static attributes with the same name:

 public final void render (Map pModel,
 HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
 // Consolidate static and dynamic model attributes
 Map model = new HashMap (this . staticAttributes) ;
 model.putAll (pModel) ;

 renderMergedOutputModel (model, request, response);


The AbstractView class exposes the following bean properties, inherited by all the view implementations discussed here: