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

  • Redirecting to another controller from SimpleFormController

    I'm a Spring's newbie

    I'm implementing an update function for an object (but this would be very helpful for other situations).

    When this update is complete I'd like to redirect to a controller rather than to a page.

    That page in this particular case would be a list of objects like the one I've succesfully updated. I could use a tag that populate the page with the correct bean, but I'd prefer mantaining a controller.

    Code:
    <property name="successView"><value>admin/classification-list</value></property>
    I use these two resolvers:

    Code:
     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix"><value>/WEB-INF/jsp/</value></property>                                 
       <property name="suffix"><value>.jsp</value></property>                                          
     </bean>                                                                                           
                                                                                                       
     <bean id="viewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
    But I don't get the actual flow. Any hints ?

    Thanks

  • #2
    I've changed my SuccessView property from

    from

    Code:
    <property name="successView"><value>admin/classification-list</value></property>
    to

    Code:
     <property name="successView"><value>redirect&#58;/admin/classification-list.htm</value></property>
    It works!! but now on the URL of the target page is something like:
    http://MYCONTEXT/admin/classificatio...lassification=mySuccesfullySubmittedFormClass%401d9d565
    If I refresh the page it seems that everything is working properly, but its just a aestethic problem.

    Any suggestion ?

    Thanks
    Fabio

    Comment


    • #3
      This works indeed.

      But I'm wondering if there isn't a cleaner solution. You have to know to what path the Controller is mapped. What if you decide later on you want to move the url of the Controller? You'd have to check all the code and change the url's.

      Does anybody know if there's a way to redirect to a specific Controller using just the name of the Controller without knowing anything about the url?

      Comment


      • #4
        You can always redirect from a SimpleFormController to another
        controller using this in your onSubmit(...):

        RedirectView view = new RedirectView("other.htm");
        return new ModelAndView(view);

        You can add objects as attributes to avoid the query string.

        Comment


        • #5
          I was talking about redirecting based on the bean name of the controller...

          Comment


          • #6
            Yes my idea was a redirection based on the name of controller something like this (I know it doesn't work):

            Code:
            <property name="successView"><ref bean="classificationListController"/></property>

            Comment

            Working...
            X