|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.web.servlet.ModelAndView
public class ModelAndView
Holder for both Model and View in the web MVC framework. Note that these are entirely distinct. This class merely holds both to make it possible for a controller to return both model and view in a single return value.
Class to represent a model and view returned by a handler used by a DispatcherServlet. The view can take the form of a reference to a View object, or a String view name which will need to be resolved by a ViewResolver object. The model is a Map, allowing the use of multiple data objects keyed by name.
DispatcherServlet
,
ViewResolver
,
HandlerAdapter.handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
,
Controller.handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
Constructor Summary | |
---|---|
ModelAndView()
Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments. |
|
ModelAndView(String viewName)
Convenient constructor when there is no model data to expose. |
|
ModelAndView(String viewName,
Map model)
Creates new ModelAndView given a view name and a model. |
|
ModelAndView(String viewName,
String modelName,
Object modelObject)
Convenient constructor to take a single model object. |
|
ModelAndView(View view)
Convenient constructor when there is no model data to expose. |
|
ModelAndView(View view,
Map model)
Creates new ModelAndView given a View object and a model. |
|
ModelAndView(View view,
String modelName,
Object modelObject)
Convenient constructor to take a single model object. |
Method Summary | |
---|---|
ModelAndView |
addAllObjects(Map modelMap)
Add all entries contained in the provided map to the model. |
ModelAndView |
addObject(String modelName,
Object modelObject)
Add an object to the model. |
void |
clear()
Clear the state of this ModelAndView object. |
Map |
getModel()
Return the model map. |
protected Map |
getModelInternal()
Return the model map. |
View |
getView()
Return the View object, or null if we are 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 we are using a View object. |
boolean |
isEmpty()
Return whether this ModelAndView object is empty, i.e. whether it does not hold any view and does not contain a model. |
boolean |
isReference()
Return whether we use a view reference, i.e. true if the view has been specified via a name to be resolved by the DispatcherServlet via a ViewResolver. |
void |
setView(View view)
Set a View object for this ModelAndView. |
void |
setViewName(String viewName)
Set a view name for this ModelAndView, to be resolved by the DispatcherServlet via a ViewResolver. |
String |
toString()
Return diagnostic information about this model and view. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ModelAndView()
setView(View)
,
setViewName(String)
public ModelAndView(View view)
addObject
.
view
- View object to renderaddObject(java.lang.String, java.lang.Object)
public ModelAndView(String viewName)
addObject
.
viewName
- name of the View to render, to be resolved
by the DispatcherServletaddObject(java.lang.String, java.lang.Object)
public ModelAndView(View view, Map model)
view
- View object to rendermodel
- Map of model names (Strings) to model objects
(Objects). Model entries may not be null
, but the model Map
may be null
if there is no model data.public ModelAndView(String viewName, Map model)
viewName
- name of the View to render, to be resolved
by the DispatcherServletmodel
- Map of model names (Strings) to model objects
(Objects). Model entries may not be null
, but the model Map
may be null
if there is no model data.public ModelAndView(View view, String modelName, Object modelObject)
view
- View object to rendermodelName
- name of the single entry in the modelmodelObject
- the single model objectpublic ModelAndView(String viewName, String modelName, Object modelObject)
viewName
- name of the View to render, to be resolved
by the DispatcherServletmodelName
- name of the single entry in the modelmodelObject
- the single model objectMethod Detail |
---|
public void setView(View view)
public View getView()
null
if we are using a view name
to be resolved by the DispatcherServlet via a ViewResolver.
public void setViewName(String viewName)
public String getViewName()
null
if we are using a View object.
public boolean isReference()
protected Map getModelInternal()
public Map getModel()
public ModelAndView addObject(String modelName, Object modelObject)
modelName
- name of the object to add to the modelmodelObject
- object to add to the model. May not be null
.
public ModelAndView addAllObjects(Map modelMap)
modelMap
- a map of modelName->modelObject pairs
public void clear()
Can be used to suppress rendering of a given ModelAndView object
in the postHandle
method of a HandlerInterceptor.
public boolean isEmpty()
clear()
public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |