• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC : Pass from one Controller to Another

 
Aashish Chande
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aashish Chande
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic