org.springframework.web.method.support
Class ModelAndViewContainer

java.lang.Object
  extended by org.springframework.web.method.support.ModelAndViewContainer

public class ModelAndViewContainer
extends Object

Provides access to the model and a place to record model and view related decisions made by HandlerMethodArgumentResolvers or a HandlerMethodReturnValueHandler.

In addition to storing model attributes and a view, the ModelAndViewContainer also provides a setResolveView(boolean) flag, which can be used to request or bypass a view resolution phase. This is most commonly used from HandlerMethodReturnValueHandlers but in some cases may also be used from HandlerMethodArgumentResolvers such as when a handler method accepts an argument providing access to the response. When that is the case, if the handler method returns null, view resolution is skipped.

Since:
3.1
Author:
Rossen Stoyanchev

Constructor Summary
ModelAndViewContainer()
          Create a ModelAndViewContainer instance with a BindingAwareModelMap.
ModelAndViewContainer(ModelMap model)
          Create a ModelAndViewContainer instance with the given ModelMap instance.
 
Method Summary
 void addAllAttributes(Map<String,?> attributes)
          Copy all attributes in the supplied Map into the model
 void addAttribute(String name, Object value)
          Add the supplied attribute under the given name.
 boolean containsAttribute(String name)
          Whether model contains an attribute of the given name.
 Object getAttribute(String name)
           
 ModelMap getModel()
           
 Object getView()
           
 String getViewName()
           
 boolean isResolveView()
           
 void mergeAttribute(String name, Object value)
          Add the given attribute if the model does not already contain such an attribute.
 void setResolveView(boolean resolveView)
           
 void setView(Object view)
           
 void setViewName(String viewName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelAndViewContainer

public ModelAndViewContainer()
Create a ModelAndViewContainer instance with a BindingAwareModelMap.


ModelAndViewContainer

public ModelAndViewContainer(ModelMap model)
Create a ModelAndViewContainer instance with the given ModelMap instance.

Parameters:
model - the model to use
Method Detail

getModel

public ModelMap getModel()
Returns:
the model for the current request

getViewName

public String getViewName()
Returns:
the view name to use for view resolution, or null

setViewName

public void setViewName(String viewName)
Parameters:
viewName - the name of the view to use for view resolution

getView

public Object getView()
Returns:
the view instance to use for view resolution

setView

public void setView(Object view)
Parameters:
view - the view instance to use for view resolution

isResolveView

public boolean isResolveView()
Returns:
whether the view resolution is requested (true), or should be bypassed (false)

setResolveView

public void setResolveView(boolean resolveView)
Parameters:
resolveView - whether the view resolution is requested (true), or should be bypassed (false)

containsAttribute

public boolean containsAttribute(String name)
Whether model contains an attribute of the given name.

Parameters:
name - the name of the model attribute
Returns:
true if the model contains an attribute by that name and the name is not an empty string

getAttribute

public Object getAttribute(String name)
Parameters:
name - the attribute to get from the model
Returns:
the attribute or null

addAttribute

public void addAttribute(String name,
                         Object value)
Add the supplied attribute under the given name.

Parameters:
name - the name of the model attribute (never null)
value - the model attribute value (can be null)

addAllAttributes

public void addAllAttributes(Map<String,?> attributes)
Copy all attributes in the supplied Map into the model


mergeAttribute

public void mergeAttribute(String name,
                           Object value)
Add the given attribute if the model does not already contain such an attribute.

Parameters:
name - the name of the attribute to check and add
value - the value of the attribute