public class ModelAndViewContainer extends 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(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 |
getDefaultModel()
Return the "default" model created at instantiation.
|
ModelMap |
getModel()
Return the model to use -- either 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 has been handled fully within the handler.
|
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. |
ModelAndViewContainer |
removeAttributes(Map<String,?> attributes)
Remove the given attributes from the model.
|
void |
setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)
By default the content of the "default" model is used both during
rendering and redirect scenarios.
|
void |
setRedirectModel(ModelMap redirectModel)
Provide a separate model instance to use in a redirect scenario.
|
void |
setRedirectModelScenario(boolean redirectModelScenario)
Whether the controller has returned a redirect instruction, e.g.
|
void |
setRequestHandled(boolean requestHandled)
Whether the request has been handled fully within the handler, e.g.
|
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.
|
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)
RedirectAttributes
and use
it to provide attributes to prepare the redirect URL.
Setting this flag to true
guarantees the "default" model is
never used in a redirect scenario even if a RedirectAttributes argument
is not declared. Setting it to false
means the "default" model
may be used in a redirect if the controller method doesn't declare a
RedirectAttributes argument.
The default setting is false
.
public void setViewName(String viewName)
public String getViewName()
null
if a View object is set.public void setView(Object view)
public Object getView()
null
if we using a view name
to be resolved by the DispatcherServlet via a ViewResolver.public boolean isViewReference()
public ModelMap getModel()
redirectModelScenario=false
or
there is no redirect model (i.e. RedirectAttributes was not declared as
a method argument) and ignoreDefaultModelOnRedirect=false
.public ModelMap getDefaultModel()
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
.
null
public void setRedirectModel(ModelMap redirectModel)
setRedirectModelScenario(boolean)
gets set to true
to signal
a redirect scenario.public void setRedirectModelScenario(boolean redirectModelScenario)
public SessionStatus getSessionStatus()
SessionStatus
instance to use that can be used to
signal that session processing is complete.public void setRequestHandled(boolean requestHandled)
@ResponseBody
method, and therefore view resolution is not
necessary. This flag can also be set when controller methods declare an
argument of type ServletResponse
or OutputStream
).
The default value is false
.
public boolean isRequestHandled()
public ModelAndViewContainer addAttribute(String name, Object value)
getModel().addAttribute(String, Object)
.public ModelAndViewContainer addAttribute(Object value)
getModel().addAttribute(Object)
.public ModelAndViewContainer addAllAttributes(Map<String,?> attributes)
getModel().addAllAttributes(Map)
.public ModelAndViewContainer mergeAttributes(Map<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(Map<String,?> attributes)
public boolean containsAttribute(String name)
getModel().containsAttribute(String)
.