com.interface21.web.servlet
Class ModelAndView

java.lang.Object
  |
  +--com.interface21.web.servlet.ModelAndView

public class ModelAndView
extends java.lang.Object

Holder for both Model and View in our MVC framework. Note that these are entirely distinct. This class merely holds both to make it possible for a controller to return both model and view in a single return value.

Class to represent a model and view returned by an handler used by a DispatcherServlet. The View can take the form of a reference to a View object, or a String view name, which will need to be resolved by a ViewResolver object. The model is a Map, allowing the use of multiple data objects.

Author:
Rod Johnson

Constructor Summary
ModelAndView(java.lang.String viewName)
          Convenient constructor when there is no model data to expose
ModelAndView(java.lang.String viewName, java.util.Map model)
          Creates new ModelAndView given a viewName and a model.
ModelAndView(java.lang.String viewName, java.lang.String modelName, java.lang.Object modelObject)
          Convenient constructor to take a single model object.
ModelAndView(View view)
          Convenient constructor when there is no model data to expose
ModelAndView(View view, java.util.Map model)
          Creates new ModelAndView given a View reference and a model.
ModelAndView(View view, java.lang.String modelName, java.lang.Object modelObject)
          Convenient constructor to take a single model object.
 
Method Summary
 ModelAndView addObject(java.lang.String name, java.lang.Object object)
          Add an object to the model.
 java.util.Map getModel()
           
 View getView()
           
 java.lang.String getViewName()
           
 boolean isReference()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModelAndView

public ModelAndView(View view)
Convenient constructor when there is no model data to expose
Parameters:
view - view reference

ModelAndView

public ModelAndView(java.lang.String viewName)
Convenient constructor when there is no model data to expose
Parameters:
viewName - view name, resolved by the controller servlet

ModelAndView

public ModelAndView(View view,
                    java.util.Map model)
Creates new ModelAndView given a View reference and a model.
Parameters:
view - view to render this model
model - Map of model names (Strings) to models (Objects). Model entries may not be null, but the model may be null if there is no model data.

ModelAndView

public ModelAndView(java.lang.String viewName,
                    java.util.Map model)
Creates new ModelAndView given a viewName and a model.
Parameters:
viewName - name of the View to render this model. This will be resolved by the DispatcherServlet at runtime.
model - Map of model names (Strings) to models (Objects). Model entries may not be null, but the model may be null if there is no model data.

ModelAndView

public ModelAndView(View view,
                    java.lang.String modelName,
                    java.lang.Object modelObject)
Convenient constructor to take a single model object.
Parameters:
view - view reference
modelName - modelName of the single entry in the modelObject
modelObject - modelObject of the single entry in the modelObject

ModelAndView

public ModelAndView(java.lang.String viewName,
                    java.lang.String modelName,
                    java.lang.Object modelObject)
Convenient constructor to take a single model object.
Parameters:
viewName - name of the view
modelName - modelName of the single entry in the modelObject
modelObject - modelObject of the single entry in the modelObject
Method Detail

addObject

public ModelAndView addObject(java.lang.String name,
                              java.lang.Object object)
Add an object to the model.
Parameters:
name - name of the object to add to the model
object - object to add to the model. May not be null.
Returns:
this object, convenient to allow usages like return modelAndView.addObject("foo", bar);

isReference

public boolean isReference()
Returns:
whether we use a view reference

getView

public View getView()
Returns:
the View reference, or null if we are using a viewName to be resolved by the DispatcherServlet.

getViewName

public java.lang.String getViewName()
Returns:
the viewName, or null if we are using a View reference

getModel

public java.util.Map getModel()
Returns:
the model map. Map be null.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
diagnostic information about this model and view


Rod Johnson and Spring contributors 2001-2003.