File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Spring MVC - ModelAttribute with MultiActionController Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring MVC - ModelAttribute with MultiActionController" Watch "Spring MVC - ModelAttribute with MultiActionController" New topic

Spring MVC - ModelAttribute with MultiActionController

Auton Flores

Joined: Sep 09, 2008
Posts: 2
Hello everybody, I need some help with this issue: I would like to get an object from a jsp page on my MultiActionController's method.

I do have a list of object Pessoa on my jsp page, and for each one object I provide action's hyperlinks to the MultiActionController's method, just like the code below. So, when the user gets these links it should be forward to the respective method with its pessoa object fullfiled. But what I'm getting now is just a null pessoa object.

What am I missing to get this to work properly?

My Action (MultiActionController):

My jsp:

I would appreciate any directions.

Regards, newbcc
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

When you said MultiActionController I thought you were extending that class in the Spring Framework (which you should not be doing anymore since version 2.5) It seems you are using the controller correctly but I would get out of the habit of calling it a MultiActionController as it is a bit misleading

Anyway your model object will be null because because your not binding it. Use the Spring form tag to create a form and bind your model object to it. Also there is no need to pass in the request and response as it appears you are not using them. Also you can just return String instead of ModelAndView where String is the view name. The ModelAttribute you pass in as a parameter will automatically be included. You are not using the "msg"

Have a look at this for an example of the things you can do with the form tag.

[How To Ask Questions][Read before you PM me]
Auton Flores

Joined: Sep 09, 2008
Posts: 2
Hello Bill,

First of all I would like to thank you for the reply.

But even if I would want to follow with this strategy is there any way for me to do it so? I mean, this example is a type of POC and I do not intend to keep writing codes using these controller. It is just for studying purpose.

By the way, the sample code I put in here it is not the original one, for this reason it is not showing the use of the pessoa and the msg objects.

I agree. Here's the link:
subject: Spring MVC - ModelAttribute with MultiActionController
It's not a secret anymore!