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()));
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());