Modification in conventional ModelAndView

In this section, you will get to known about the new modification in conventional ModelAndView.

Ads

Tutorials   
Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration Interceptors Configuration using Java or XML Customizing the MVC Java config or XML Namespace MVC Java Config or the MVC XML Namespace Servlet container initialization through code Support for ETag The checkbox tag Autogenerated logical view name through RequestToViewNameTranslator Modification in conventional ModelAndView ControllerClassNameHandlerMapping class for handling convention mapping The password tag The input tag The form tag Form Tag library configuration Customizing the Default Error Page @ExceptionHandler & @ResponseStatus annotation Multipart support for file upload in Spring MVC Themes and Theme resolvers in Spring MVC Locales in Spring MVC ContentNegotiatingViewResolver Redirecting and forwarding to views Chaining of Multiple view resolvers View Resolving through ViewResolver interface Requests Intercepting through a HandlerInterceptor Defining handler methods using @RequestMapping annotation Spring 3.2 Asynchronous Request Processing @RequestMapping annotation for mapping requests @Controller annotation for defining new controller
Ads

Modification in conventional ModelAndView

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 :

  • If a a.b.Employee class instance is added, name employee will be generated.

  • If a.b.Payroll instance is added , the name payroll will be generated.

  • If java.util.HashMap instance is added, the name hashMap will be generated.

  • If null will be added, an IllegalArgumentException will be thrown.

Rules for automatic resolution of the name of the added collections object such as a Set or a List is :

  • If no or , zero or more x.y.Employee element is added to x.y.Employee[] array, name employeeList will be generated.

  • If no or , zero or more x.y.Employee element is added to x.y.Foo[] array, name fooList will be generated.

  • If one or more a.b.Employee elements are added to java.util.ArrayList, the name employeeList will be generated.

  • If one or more a.b.Foo elements are added to java.util.HashSet, the name fooList will be generated.

  • An empty java.util.ArrayList should not be added.



Advertisements

Ads
Share on Google+Share on Google+

Modification in conventional ModelAndView

Posted on: January 30, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Modification in conventional ModelAndView  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads