Announcement Announcement Module
Collapse
No announcement yet.
redirect view after onSubmit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • redirect view after onSubmit

    all my controllers have a formBackingObject, referenceData and onBindAndValidate, onSubmit methods
    I would like after a successful onSubmit to redirect to another formController ( going through formBackingObject and referenceData methods)

    In a previous message you suggested using redirectView. Could you give me an idea of the code that must be inserted at the end of the onSubmit method.

    Right now my onSubmit ends with
    return new ModelAndView(viewName, model)
    Thanks

  • #2
    Yep.

    Just add this to the file "views.properties"

    Code:
    myRedirectView.class=org.springframework.web.servlet.view.RedirectView
    myRedirectView.url=someRedirectUrl.htm
    BTW: I recommend you look into the \samples\petclinic application in Spring distribution.

    Good luck!

    Comment


    • #3
      views.properties ???

      What is that ?

      Comment


      • #4
        An alternative way, if you want to decouple your controller from the way the response gets handled, is using the redirect prefix:

        Make your view resolver a UrlBasedViewResolver as follows
        Code:
        <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        		<property name="prefix" value="/WEB-INF/...your path to views..../"/>
        		<property name="suffix" value=".jsp"/>
        		<property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView"/>
        </bean>
        Then in your controller bean definition...
        Code:
        <property name="successView" value="redirect:myOtherRequestUrl"/>
        where myOtherRequestUrl is the url that maps to the second controller

        hope this helps a bit

        Comment


        • #5
          <property name="successView" value="redirect:myOtherRequestUrl"/>

          myOtherRequestUrl is the url mapped to the other controller ..

          For me myOtherRequestUrl is just a static page without any form element and so i dont have a controller for this page .. its just a view .. So how do i redirect to a view without a controller ?

          Comment


          • #6
            You dont need to redirect then...

            Comment


            • #7
              Originally posted by springbaby View Post
              For me myOtherRequestUrl is just a static page without any form element and so i dont have a controller for this page .. its just a view .. So how do i redirect to a view without a controller ?
              It doesnt matter whether its mapped to Spring MVC or not.
              Redirection URL may even point to different server.

              Comment

              Working...
              X