In this section, you will get to known about the new modification in conventional ModelAndView.
The modifications in ModelAndView is inspired by the ModelMap class and ModelAndView also uses ModelMap to implement those inspired modifications.
In ModelMap , if a single object is added using addObject() method, a key is automatically generated by it. Also, when an object is added to the ModelAndView , it uses ModelMap to automatically generate associated key.
To understand it completely, take a look at the below controller code :
public class WritingController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
List selectedItems = // get a List of selected objects
Employee employee = //get the instance of the class Employee
ModelAndView model= new ModelAndView("displayUserAccount"); <-- the logical view name
model.addObject(selectedItems); <-- no name, just the object
model.addObject(employee); <-- again an object is added with no name
return model;
}
}
Two things comes out from above example :
First, you can add multiple object to the same ModelAndView.
Second thing is that a list and class instance is added but no name is added with objects. Now, the name is resolved under the following rules :
Rules for automatic resolution of the name of the added scalar object such as a class instance is :
Rules for automatic resolution of the name of the added collections object such as a Set or a List is :
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Modification in conventional ModelAndView
Post your Comment