Announcement Announcement Module
No announcement yet.
Chaining controller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Chaining controller

    I would like to know if it is possible after processing a Controller to redirect to another Controller.

    After filling up a form and inserting the data in the database(InsertController) I want to show a list of all values(ListController)
    This are 2 different actions so should be in different Controllers, how can configure this in Spring MVC?

  • #2
    One solution is to return a new RedirectView(url). This is very handy when user hits F5 (refresh the page). Only the last controller (ListController) will be invoked.


    • #3
      That means that the chaining must be done when I return de ModelView.

      I cannot configure that in the bean declaration on the sucessView property of the SimpleFormController.


      • #4
        If you are using the multiactioncontrollers, then you could do this by just invoking the correct method of the multiactioncontroller. Otherwise I dont know how it should be easy possible in the springframework, and this issue was one of the reasons I started so I could handle these situations easily. And I wanted to have all the navigation stuff in a separate file so I could easily remove links on certain pages.

        Basically, in a controller when you want to redirect, you throw a WorkflowRedirectException("workflowname.pageflowna me.pagename") and the springworkflow will go there. If you add a model to the exception, then the model will be available in the next controller as well. So for instance you could save in one controller, add a saved message to the model and then redirect to another controller, and the saved message will still be available.



        • #5
          redirect controller to controller with request object?

          redirectView only mak url redirection.
          if we use render method of redirectView and add request parameter to Map, we send request parameters to other controller, so other controller can take request parameter as follow
          String username=request.getParameter("username");
          but our controller need to use attributes of request for object values,

          User user = (User) request.getAttribute("user");

          in this case we sent request object controller to other controller
          how can I do?


          • #6
            Were you able to resolve this?


            • #7
              Well, digging out a 6 years-old thread...everything has changed since then in the Spring world, with Spring 3.0 web mvc just return "forward:nextURL" in your controller's method after you have processed data from the first page. As simple as that...