public class ModelAndViewContainer
extends java.lang.Object
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.
Constructor and Description |
---|
ModelAndViewContainer() |
Modifier and Type | Method and Description |
---|---|
ModelAndViewContainer |
addAllAttributes(java.util.Map<java.lang.String,?> attributes)
Copy all attributes to the underlying model.
|
ModelAndViewContainer |
addAttribute(java.lang.Object value)
Add the supplied attribute to the underlying model.
|
ModelAndViewContainer |
addAttribute(java.lang.String name,
java.lang.Object value)
Add the supplied attribute to the underlying model.
|
boolean |
containsAttribute(java.lang.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. |
java.lang.Object |
getView()
Return the View object, or
null if we using a view name
to be resolved by the DispatcherServlet via a ViewResolver. |
java.lang.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(java.util.Map<java.lang.String,?> attributes)
Copy attributes in the supplied
Map with existing objects of
the same name taking precedence (i.e. |
ModelAndViewContainer |
removeAttributes(java.util.Map<java.lang.String,?> attributes)
Remove the given attributes from the model.
|
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(java.lang.Object view)
Set a View object to be used by the DispatcherServlet.
|
void |
setViewName(java.lang.String viewName)
Set a view name to be resolved by the DispatcherServlet via a ViewResolver.
|
java.lang.String |
toString()
Return diagnostic information.
|
public void setViewName(java.lang.String viewName)
public java.lang.String getViewName()
null
if a View object is set.public void setView(java.lang.Object view)
public java.lang.Object getView()
null
if we using a view name
to be resolved by the DispatcherServlet via a ViewResolver.public boolean isViewReference()
public void setRequestHandled(boolean requestHandled)
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
.
public boolean isRequestHandled()
public ModelMap getModel()
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
.
public void setRedirectModel(ModelMap redirectModel)
setRedirectModelScenario(boolean)
gets set to true
to signal
a redirect scenario.public void setRedirectModelScenario(boolean redirectModelScenario)
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)
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
.
public SessionStatus getSessionStatus()
SessionStatus
instance to use that can be used to
signal that session processing is complete.public ModelAndViewContainer addAttribute(java.lang.String name, java.lang.Object value)
getModel().addAttribute(String, Object)
.public ModelAndViewContainer addAttribute(java.lang.Object value)
getModel().addAttribute(Object)
.public ModelAndViewContainer addAllAttributes(java.util.Map<java.lang.String,?> attributes)
getModel().addAllAttributes(Map)
.public ModelAndViewContainer mergeAttributes(java.util.Map<java.lang.String,?> attributes)
Map
with existing objects of
the same name taking precedence (i.e. not getting replaced).
A shortcut for getModel().mergeAttributes(Map<String, ?>)
.public ModelAndViewContainer removeAttributes(java.util.Map<java.lang.String,?> attributes)
public boolean containsAttribute(java.lang.String name)
getModel().containsAttribute(String)
.public java.lang.String toString()
toString
in class java.lang.Object