Save This Page
Home » Spring-Framework-090522 » org.springframework » web » servlet » [javadoc | source]
org.springframework.web.servlet
public class: ModelAndView [javadoc | source]
java.lang.Object
   org.springframework.web.servlet.ModelAndView
Holder for both Model and View in the web 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.

Represents a model and view returned by a handler, to be resolved by a DispatcherServlet. The view can take the form of a String view name which will need to be resolved by a ViewResolver object; alternatively a View object can be specified directly. The model is a Map, allowing the use of multiple objects keyed by name.

Constructor:
 public ModelAndView() 
 public ModelAndView(String viewName) 
    Convenient constructor when there is no model data to expose. Can also be used in conjunction with addObject.
    Parameters:
    viewName - name of the View to render, to be resolved by the DispatcherServlet's ViewResolver
    Also see:
    addObject
 public ModelAndView(View view) 
    Convenient constructor when there is no model data to expose. Can also be used in conjunction with addObject.
    Parameters:
    view - View object to render
    Also see:
    addObject
 public ModelAndView(String viewName,
    Map model) 
    Creates new ModelAndView given a view name and a model.
    Parameters:
    viewName - name of the View to render, to be resolved by the DispatcherServlet's ViewResolver
    model - Map of model names (Strings) to model objects (Objects). Model entries may not be null, but the model Map may be null if there is no model data.
 public ModelAndView(View view,
    Map model) 
    Creates new ModelAndView given a View object and a model. Note: the supplied model data is copied into the internal storage of this class. You should not consider to modify the supplied Map after supplying it to this class
    Parameters:
    view - View object to render
    model - Map of model names (Strings) to model objects (Objects). Model entries may not be null, but the model Map may be null if there is no model data.
 public ModelAndView(String viewName,
    String modelName,
    Object modelObject) 
    Convenient constructor to take a single model object.
    Parameters:
    viewName - name of the View to render, to be resolved by the DispatcherServlet's ViewResolver
    modelName - name of the single entry in the model
    modelObject - the single model object
 public ModelAndView(View view,
    String modelName,
    Object modelObject) 
    Convenient constructor to take a single model object.
    Parameters:
    view - View object to render
    modelName - name of the single entry in the model
    modelObject - the single model object
Method from org.springframework.web.servlet.ModelAndView Summary:
addAllObjects,   addObject,   addObject,   clear,   getModel,   getModelInternal,   getModelMap,   getView,   getViewName,   hasView,   isEmpty,   isReference,   setView,   setViewName,   toString,   wasCleared
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.web.servlet.ModelAndView Detail:
 public ModelAndView addAllObjects(Map modelMap) 
    Add all attributes contained in the provided Map to the model.
 public ModelAndView addObject(Object attributeValue) 
    Add an attribute to the model using parameter name generation.
 public ModelAndView addObject(String attributeName,
    Object attributeValue) 
    Add an attribute to the model.
 public  void clear() 
    Clear the state of this ModelAndView object. The object will be empty afterwards.

    Can be used to suppress rendering of a given ModelAndView object in the postHandle method of a HandlerInterceptor.

 public Map getModel() 
    Return the model map. Never returns null. To be called by application code for modifying the model.
 protected Map getModelInternal() 
    Return the model map. May return null. Called by DispatcherServlet for evaluation of the model.
 public ModelMap getModelMap() 
    Return the underlying ModelMap instance (never null).
 public View getView() 
    Return the View object, or null if we are using a view name to be resolved by the DispatcherServlet via a ViewResolver.
 public String getViewName() 
    Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if we are using a View object.
 public boolean hasView() 
    Indicate whether or not this ModelAndView has a view, either as a view name or as a direct View instance.
 public boolean isEmpty() 
    Return whether this ModelAndView object is empty i.e. whether it does not hold any view and does not contain a model.
 public boolean isReference() 
    Return whether we use a view reference, i.e. true if the view has been specified via a name to be resolved by the DispatcherServlet via a ViewResolver.
 public  void setView(View view) 
    Set a View object for this ModelAndView. Will override any pre-existing view name or View.
 public  void setViewName(String viewName) 
    Set a view name for this ModelAndView, to be resolved by the DispatcherServlet via a ViewResolver. Will override any pre-existing view name or View.
 public String toString() 
    Return diagnostic information about this model and view.
 public boolean wasCleared() 
    Return whether this ModelAndView object is empty as a result of a call to #clear i.e. whether it does not hold any view and does not contain a model. Returns false if any additional state was added to the instance after the call to #clear .