## org.springframework.web.method.support
Class ModelAndViewContainer

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

    public class ModelAndViewContainer

extends Object

Records model and view related decisions made by `HandlerMethodArgumentResolver`s and `HandlerMethodReturnValueHandler`s during the course of invocation of a controller method.

The `setRequestHandled(boolean)` flag can be used to indicate the request has been handled directly and view resolution is not required.

A default `Model` is automatically created at instantiation. An alternate model instance may be provided via `setRedirectModel(org.springframework.ui.ModelMap)` for use in a redirect scenario. When `setRedirectModelScenario(boolean)` is set to `true` signalling a redirect scenario, the `getModel()` returns the redirect model instead of the default model.

Since:
  3.1
Author:
  Rossen Stoyanchev

Constructor Summary
`ModelAndViewContainer()` Create a new instance.

Method Summary
`ModelAndViewContainer` `addAllAttributes(Map<String,?> attributes)` Copy all attributes to the underlying model.
`ModelAndViewContainer` `addAttribute(Object value)` Add the supplied attribute to the underlying model.
`ModelAndViewContainer` `addAttribute(String name, Object value)` Add the supplied attribute to the underlying model.
`boolean` `containsAttribute(String name)` Whether the underlying model contains the given attribute name.
`ModelMap` `getModel()` Return the model to use: the "default" or the "redirect" model.
`SessionStatus` `getSessionStatus()` Return the `SessionStatus` instance to use that can be used to signal that session processing is complete.
`Object` `getView()` Return the View object, or `null` if we using a view name to be resolved by the DispatcherServlet via a ViewResolver.
`String` `getViewName()` Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or `null` if a View object is set.
`boolean` `isRequestHandled()` Whether the request is handled directly.
`boolean` `isViewReference()` Whether the view is a view reference specified via a name to be resolved by the DispatcherServlet via a ViewResolver.
`ModelAndViewContainer` `mergeAttributes(Map<String,?> attributes)` Copy attributes in the supplied `Map` with existing objects of the same name taking precedence (i.e.
`void` `setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)` When set to `true` the default model is never used in a redirect scenario.
`void` `setRedirectModel(ModelMap redirectModel)` Provide a separate model instance to use in a redirect scenario.
`void` `setRedirectModelScenario(boolean redirectModelScenario)` Signal the conditions are in place for using a redirect model.
`void` `setRequestHandled(boolean requestHandled)` Signal a scenario where the request is handled directly.
`void` `setView(Object view)` Set a View object to be used by the DispatcherServlet.
`void` `setViewName(String viewName)` Set a view name to be resolved by the DispatcherServlet via a ViewResolver.
`String` `toString()` Return diagnostic information.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ModelAndViewContainer

    public ModelAndViewContainer()

  Create a new instance.

Method Detail

### setViewName

    public void setViewName(String viewName)

  Set a view name to be resolved by the DispatcherServlet via a ViewResolver. Will override any pre-existing view name or View.

### getViewName

    public String getViewName()

  Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or `null` if a View object is set.

### setView

    public void setView(Object view)

  Set a View object to be used by the DispatcherServlet. Will override any pre-existing view name or View.

### getView

    public Object getView()

  Return the View object, or `null` if we using a view name to be resolved by the DispatcherServlet via a ViewResolver.

### isViewReference

    public boolean isViewReference()

  Whether the view is a view reference specified via a name to be resolved by the DispatcherServlet via a ViewResolver.

### setRequestHandled

    public void setRequestHandled(boolean requestHandled)

  Signal a scenario where the request is handled directly.

  A `HandlerMethodReturnValueHandler` may use this flag to indicate the response has been fully handled and view resolution is not required (e.g. `@ResponseBody`).

  A `HandlerMethodArgumentResolver` may also use this flag to indicate the presence of an argument (e.g. `ServletResponse` or `OutputStream`) that may lead to a complete response depending on the method return value.

  The default value is `true`.

### isRequestHandled

    public boolean isRequestHandled()

  Whether the request is handled directly.

### getModel

    public ModelMap getModel()

  Return the model to use: the "default" or the "redirect" model.

  The default model is used if `"redirectModelScenario=false"` or if the redirect model is `null` (i.e. it wasn't declared as a method argument) and `ignoreDefaultModelOnRedirect=false`.

### setRedirectModel

    public void setRedirectModel(ModelMap redirectModel)

  Provide a separate model instance to use in a redirect scenario. The provided additional model however is not used used unless `setRedirectModelScenario(boolean)` gets set to `true` to signal a redirect scenario.

### setRedirectModelScenario

    public void setRedirectModelScenario(boolean redirectModelScenario)

  Signal the conditions are in place for using a redirect model. Typically that means the controller has returned a redirect instruction.

### setIgnoreDefaultModelOnRedirect

    public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)

  When set to `true` the default model is never used in a redirect scenario. So if a redirect model is not available, an empty model is used instead.

  When set to `false` the default model can be used in a redirect scenario if a redirect model is not available.

  The default setting is `false`.

### getSessionStatus

    public SessionStatus getSessionStatus()

  Return the `SessionStatus` instance to use that can be used to signal that session processing is complete.

### addAttribute

    public ModelAndViewContainer addAttribute(String name,
                                              Object value)

  Add the supplied attribute to the underlying model.

  See Also:
    `ModelMap.addAttribute(String, Object)`

### addAttribute

    public ModelAndViewContainer addAttribute(Object value)

  Add the supplied attribute to the underlying model.

  See Also:
    `Model.addAttribute(Object)`

### addAllAttributes

    public ModelAndViewContainer addAllAttributes(Map<String,?> attributes)

  Copy all attributes to the underlying model.

  See Also:
    `ModelMap.addAllAttributes(Map)`

### mergeAttributes

    public ModelAndViewContainer mergeAttributes(Map<String,?> attributes)

  Copy attributes in the supplied `Map` with existing objects of the same name taking precedence (i.e. not getting replaced).

  See Also:
    `ModelMap.mergeAttributes(Map)`

### containsAttribute

    public boolean containsAttribute(String name)

  Whether the underlying model contains the given attribute name.

  See Also:
    `ModelMap.containsAttribute(String)`

### toString

    public String toString()

  Return diagnostic information.

  Overrides:
    `toString` in class `Object`