PDA

View Full Version : ModelAndView


scott
Aug 10th, 2007, 01:25 PM
I can understand the ModelAndView("/pages/test.jsp") will launch the test.jsp page.

1)Then what are the usage of the last two parameters: "testForm", testForm, as in the following:


TestForm testForm = new TestForm();

modelAndView = new ModelAndView("/pages/test.jsp", "testForm", testForm);

2) What are the differences between ModelAndView which is with only one parameter and the one with more than one parameters?


Thanks


Scott

Jörg Heinicke
Aug 11th, 2007, 04:29 PM
Do you know why it is named ModelAndView ;)
test.jsp is the view in your case the rest the model (http://static.springframework.org/spring/docs/2.0.x/reference/mvc.html#mvc-coc-modelmap). But you should really consider reading the MVC chapter (http://static.springframework.org/spring/docs/2.0.x/reference/mvc.html) of the reference - and not specify the JSP in the controller directly.

Joerg

scott
Aug 12th, 2007, 06:03 PM
Thanks for the response. I'll certainly read your recommended MVC chapter later.

If you can, please reply to my question 2) , which is

What is the difference between the

ModelAndView("/page/test.jsp")

AND

ModelAndView("/page/test.jsp", "testForm", testForm)

Why sometime the last two parameters are purposely missed?


Thanks

Scott

Jörg Heinicke
Aug 12th, 2007, 06:09 PM
As I already wrote it is the model. The testForm object is made available under the key "testForm" in the JSP. Since you do not always need an explicit model you can initialize ModelAndView with just the view information.

Joerg