aspose file tools*
The moose likes Other Application Frameworks and the fly likes Spring MVC : Pass from one Controller to Another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring MVC : Pass from one Controller to Another" Watch "Spring MVC : Pass from one Controller to Another" New topic
Author

Spring MVC : Pass from one Controller to Another

Aashish Chande
Greenhorn

Joined: Jan 14, 2009
Posts: 3
Hi All,

I have a requirement, where I have a search module with modify button at the button. So when I select the items in checkbox and click on modify it will invoke a different controller I presume. Is there a way in Spring MVC 2.5 I can pass the information from one controller to another with the value from model(items check). I dont know much on redirect, whether it will solve the problem. Can someone help.

Thanks in advance
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

You can have one controller with multiple methods. So the Search button calls one method on the Controller, and the Modify button calls a different method on the same controller.

Or your Search button calls one controller, and the modify calls a different controller, the "parameters" can still be there, it is the data from the page that you are passing to the controllers.

You wouldn't have a controller call another controller, or that data just sits in one controller and can't be accessed unless the code is in that controller. Because the controller does not own the data.

I hope that helps.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Aashish Chande
Greenhorn

Joined: Jan 14, 2009
Posts: 3
Hi Mark,

Thanks for your reply. I am infact planning to put a method for modify button in same controller; but when modify button is pressed the event will pass items to be modifed to another screen where all this data will be displayed in different format(lets say a grid). In this case, I am wondering if I do a redirect to another screen whether data will be sent or do I have to wrap it and send it.

There are several scenarios in my mind,

1. Should I just define a view and return model view
2. redirect:page name
3. forward


I have not started any code on that and I am confused, but since I am working on design I need to do this immediately and dont have time to develop and test.

Any help in this will be appreciated.


Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

You need to think in the request/response mechanisms of the web, and not something that is Spring MVC specific. If I have data in one page, and I want a different page to display the same data, then I need to put the data somewhere both pages can find it. Like the session. This might also be a case where you would want to look at the Form Controller subclasses, or use Spring WebFlow.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC : Pass from one Controller to Another