Announcement Announcement Module
Collapse
No announcement yet.
Success redirect from one controller to another Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Success redirect from one controller to another

    Hi All,

    I've been testing a number of functionalities with the Springframework and in this particular case I have a simpleform controller's successview set to a redirect: payment.form which is the url mapping for another simpleform controller. I'm not sure if the redirect is causing this but the page that loads up has the url:

    http://localhost/payment.form?comman...lt%3A+0+errors

    which is quite messy and I wish to hide all this information apart from the payment.form. Reason I am going from one controller to another is that both pages have forms where a user should be directed to the next page if the first is valid (and I do some processing afterwards). I also do some processing prior to displaying the second form hence why I don't just display a standard view (i.e. jsp) after the first form.

    It is working in it's current form but I dislike the url displaying the package name and other technical information to a user. I could use a wizard form but that is overkill for what I am working on and I don't need the extra complexity of setting up a wizard form.

    Am I doing something wrong, please advise.

    Thanks,
    Tony

  • #2
    I've done this before without issue.

    Code:
    <bean id="someController" class="SomeControllerClass">
      <property name="successView" value="redirect:step2.html" />
      ...
    </bean>
    Code:
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception
    {
      SomeObj userInput = (SomeObj)command;
      someServiceObj.doSomethingWithUserInput(userInput);
      ModelAndView next = new ModelAndView(getSuccessView());
      return next;
    }
    And, if you need to pass some info along to the subsequent pages, you can put in a line like

    Code:
    next.addObject("urlParamName", someValue);
    HTH,
    Mike

    Comment


    • #3
      Thanks for that Mike. I have the same setup in my xml config file and my controller and it works, I never had a problem redirecting, it just displays extra information in the url (namely the command bean and the validator class - which I configured in the xml config, I never pass anything explicitly).

      The difference in mine and yours is that my redirect target is a url mapping to another controller, not a static html page which is where the problem is I believe.

      Comment


      • #4
        You must be using passing an existing model to your ModelAndView constructor. I'm instantiating my new ModelAndView with only the view name. Then, I can add to the empty model if I choose to instead of inheriting the one that came through the request.

        The redirects are to dynamic form controllers (the *.html URL just maps to a controller). I also have validator, command class, etc. defined in my XML for the controllers.

        Comment


        • #5
          Hi Mike,

          Thanks again - I was returning this:

          Code:
          return super.onSubmit(request, response, command, errors);
          as opposed to returning a new ModelAndView with the success view.

          Cheers,
          Tony

          Comment

          Working...
          X