Class ModelAndViewContainer
HandlerMethodArgumentResolvers and
 HandlerMethodReturnValueHandlers 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 signaling a redirect scenario, the getModel()
 returns the redirect model instead of the default model.
- Since:
- 3.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionaddAllAttributes(Map<String, ?> attributes) Copy all attributes to the underlying model.addAttribute(Object value) Add the supplied attribute to the underlying model.addAttribute(String name, Object value) Add the supplied attribute to the underlying model.booleancontainsAttribute(String name) Whether the underlying model contains the given attribute name.Return the "default" model created at instantiation.getModel()Return the model to use -- either the "default" or the "redirect" model.Return theSessionStatusinstance to use that can be used to signal that session processing is complete.Return the configured HTTP status, if any.getView()Return the View object, ornullif we are using a view name to be resolved by the DispatcherServlet via a ViewResolver.Return the view name to be resolved by the DispatcherServlet via a ViewResolver, ornullif a View object is set.booleanisBindingDisabled(String name) Whether binding is disabled for the given model attribute.booleanWhether the request has been handled fully within the handler.booleanWhether the view is a view reference specified via a name to be resolved by the DispatcherServlet via a ViewResolver.mergeAttributes(Map<String, ?> attributes) Copy attributes in the suppliedMapwith existing objects of the same name taking precedence (i.e.removeAttributes(Map<String, ?> attributes) Remove the given attributes from the model.voidsetBinding(String attributeName, boolean enabled) Register whether data binding should occur for a corresponding model attribute, corresponding to an@ModelAttribute(binding=true/false)declaration.voidsetBindingDisabled(String attributeName) Programmatically register an attribute for which data binding should not occur, not even for a subsequent@ModelAttributedeclaration.voidsetIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) Deprecated.as of 6.0 without a replacement; once removed, the default model will always be ignored on redirectvoidsetRedirectModel(ModelMap redirectModel) Provide a separate model instance to use in a redirect scenario.voidsetRedirectModelScenario(boolean redirectModelScenario) Whether the controller has returned a redirect instruction, e.g.voidsetRequestHandled(boolean requestHandled) Whether the request has been handled fully within the handler, e.g.voidsetStatus(HttpStatusCode status) Provide an HTTP status that will be passed on to with theModelAndViewused for view rendering purposes.voidSet a View object to be used by the DispatcherServlet.voidsetViewName(String viewName) Set a view name to be resolved by the DispatcherServlet via a ViewResolver.toString()Return diagnostic information.
- 
Constructor Details- 
ModelAndViewContainerpublic ModelAndViewContainer()
 
- 
- 
Method Details- 
setIgnoreDefaultModelOnRedirect@Deprecated(since="6.0") public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) Deprecated.as of 6.0 without a replacement; once removed, the default model will always be ignored on redirectBy default, the content of the "default" model is used both during rendering and redirect scenarios. Alternatively controller methods can declare an argument of typeRedirectAttributesand use it to provide attributes to prepare the redirect URL.Setting this flag to trueguarantees the "default" model is never used in a redirect scenario even if a RedirectAttributes argument is not declared. Setting it tofalsemeans the "default" model may be used in a redirect if the controller method doesn't declare a RedirectAttributes argument.As of 6.0, this property is set to trueby default.
- 
setViewNameSet a view name to be resolved by the DispatcherServlet via a ViewResolver. Will override any pre-existing view name or View.
- 
getViewNameReturn the view name to be resolved by the DispatcherServlet via a ViewResolver, ornullif a View object is set.
- 
setViewSet a View object to be used by the DispatcherServlet. Will override any pre-existing view name or View.
- 
getViewReturn the View object, ornullif we are using a view name to be resolved by the DispatcherServlet via a ViewResolver.
- 
isViewReferencepublic boolean isViewReference()Whether the view is a view reference specified via a name to be resolved by the DispatcherServlet via a ViewResolver.
- 
getModelReturn the model to use -- either the "default" or the "redirect" model. The default model is used ifredirectModelScenario=falseor there is no redirect model (i.e. RedirectAttributes was not declared as a method argument) andignoreDefaultModelOnRedirect=false.
- 
getDefaultModelReturn the "default" model created at instantiation.In general it is recommended to use getModel()instead which returns either the "default" model (template rendering) or the "redirect" model (redirect URL preparation). Use of this method may be needed for advanced cases when access to the "default" model is needed regardless, e.g. to save model attributes specified via@SessionAttributes.- Returns:
- the default model (never null)
- Since:
- 4.1.4
 
- 
setRedirectModelProvide a separate model instance to use in a redirect scenario.The provided additional model however is not used unless setRedirectModelScenario(boolean)gets set totrueto signal an actual redirect scenario.
- 
setRedirectModelScenariopublic void setRedirectModelScenario(boolean redirectModelScenario) Whether the controller has returned a redirect instruction, e.g. a "redirect:" prefixed view name, a RedirectView instance, etc.
- 
setStatusProvide an HTTP status that will be passed on to with theModelAndViewused for view rendering purposes.- Since:
- 4.3
 
- 
getStatusReturn the configured HTTP status, if any.- Since:
- 4.3
 
- 
setBindingDisabledProgrammatically register an attribute for which data binding should not occur, not even for a subsequent@ModelAttributedeclaration.- Parameters:
- attributeName- the name of the attribute
- Since:
- 4.3
 
- 
isBindingDisabledWhether binding is disabled for the given model attribute.- Since:
- 4.3
 
- 
setBindingRegister whether data binding should occur for a corresponding model attribute, corresponding to an@ModelAttribute(binding=true/false)declaration.Note: While this flag will be taken into account by isBindingDisabled(java.lang.String), a hardsetBindingDisabled(java.lang.String)declaration will always override it.- Parameters:
- attributeName- the name of the attribute
- Since:
- 4.3.13
 
- 
getSessionStatusReturn theSessionStatusinstance to use that can be used to signal that session processing is complete.
- 
setRequestHandledpublic void setRequestHandled(boolean requestHandled) Whether the request has been handled fully within the handler, e.g.@ResponseBodymethod, and therefore view resolution is not necessary. This flag can also be set when controller methods declare an argument of typeServletResponseorOutputStream).The default value is false.
- 
isRequestHandledpublic boolean isRequestHandled()Whether the request has been handled fully within the handler.
- 
addAttributeAdd the supplied attribute to the underlying model. A shortcut forgetModel().addAttribute(String, Object).
- 
addAttributeAdd the supplied attribute to the underlying model. A shortcut forgetModel().addAttribute(Object).
- 
addAllAttributesCopy all attributes to the underlying model. A shortcut forgetModel().addAllAttributes(Map).
- 
mergeAttributesCopy attributes in the suppliedMapwith existing objects of the same name taking precedence (i.e. not getting replaced). A shortcut forgetModel().mergeAttributes(Map<String, ?>).
- 
removeAttributesRemove the given attributes from the model.
- 
containsAttributeWhether the underlying model contains the given attribute name. A shortcut forgetModel().containsAttribute(String).
- 
toStringReturn diagnostic information.
 
-