Results 1 to 2 of 2

Thread: How do I pass a parameter to a successView?

  1. #1

    Default How do I pass a parameter to a successView?

    I have a list page that takes a query string parameter (userListForm.htm?groupId=123). When someone clicks on a username in the list page, it will take them to a detail page (userEditForm.htm?userId=456). In my UserEditFormController (extends SimpleFormController) upon a successful submit/save I would like to display the userList.htm page so I have defined my successView as shown below:

    <bean id="userEditFormController " class="com.xxx.UserEditFormController ">
    <property name="commandName"><value>user</value></property>
    <property name="formView"><value>userEditform</value></property>
    <property name="successView"><value>userListForm</value></property>
    </bean>

    and here is my onSubmit method in the UserEditFormController:

    protected ModelAndView onSubmit(Object command) throws Exception {

    User user = (User)command;
    boolean result = userService.save(user);
    if(result)
    return new ModelAndView(getSuccessView());
    else
    return new ModelAndView(getFormView());

    }

    I need to pass the groupId to userListForm.htm which is my successView. How can I do this declaritively?

    I know I can do the following but I am looking for a better way.

    return new ModelAndView(new RedirectView("userListForm.htm?groupId=" + user.getGroupId()));
    cheers,
    Lili

  2. #2
    Join Date
    Mar 2005
    Location
    San Francisco, CA
    Posts
    114

    Default Re: How do I pass a parameter to a successView?

    When you do a redirect, the model is converted to query parameters. So you can do this...

    return new ModelAndView(new RedirectView("userListForm.htm"),"groupId",user.ge tGroupId());

    Or more declaritively, change your bean defintion to use "redirect:"

    <bean id="userEditFormController " class="com.xxx.UserEditFormController ">
    <property name="commandName"><value>user</value></property>
    <property name="formView"><value>userEditform</value></property>
    <property name="successView"><value>redirect:userListForm</value></property>
    </bean>

    Then you can use this...

    return new ModelAndView(getSuccessView(),"groupId",user.getGr oupId());

Similar Threads

  1. pass parameter to start of flow
    By garethmorgan in forum Web Flow
    Replies: 4
    Last Post: Apr 21st, 2008, 08:46 PM
  2. Replies: 7
    Last Post: Sep 13th, 2005, 01:45 AM
  3. how to pass a parameter to a constructor
    By moacir_ha@yahoo.com.br in forum Container
    Replies: 3
    Last Post: Sep 1st, 2005, 03:06 PM
  4. Replies: 2
    Last Post: Apr 21st, 2005, 01:14 PM
  5. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •