views:

51

answers:

2

Hi,

I have two controllers , a simple form controller and a multiaction controller.

Now, in simpleformcontroller, i want to redirect a request to multiaction controller.

Here's code snippet in simpleformcontroller

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
MyObject myOb = (MyObject )command;
system.out.println(myOb.toString);
ModelAndView mav = new ModelAndView(new RedirectView("another.htm"));
mav.addObject("Obj",myOb);
return mav;
}

another.htm binds to a method in multiaction controller.

<bean id="MyController" class="MyController">
<property name="methodNameResolver">
<bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
                <property name="mappings">
                    <props>
                        <prop key="/another.htm">another</prop>
                    </props>
        </property>
  </bean>
</bean>

and the code in multiactioncontroller is

public class MyController extends MultiActionController {
    public ModelAndView another(HttpServletRequest request,
            HttpServletResponse response, MyObject myObj)   {
        system.out.println(myObj.toString());

}


}

The output is, all fields of Myobj are nulls in mutiactioncontroller whereas they have valid values when passed in simpleformcontroller.

Am i missing something here or is this not the right way to pass command objects ?

Any help is appreciated.

A: 

Unless you store your MyObject in The session, you will always get null. It occurs because The user data does not survive redirect. To store your command object in The session, use setSessionForm in The SimpleFormController and Then retrieve your command by using

public ModelAndView another(HttpServletRequest request, HttpServletResponse response, HttpSession session, MyObject myObj) throws CRPMException  {

instead

Arthur Ronald F D Garcia
Thanks for your response. That helped.
JWhiz
A: 

Here's an example that might help steer you in the right direction. It uses annotated controllers, which have effectively replaced the old-style controllers that you are attempting to use.

James Earl Douglas