PDA

View Full Version : Another newbiew question re form control


mikehalfsheen
Nov 29th, 2004, 11:13 AM
<caveat> Usual please bear with me stuff </caveat>
I have a form (lets call it FormA, in formA.jsp) with a SimpleFormController . namely FormAController.

formA.jsp has a link to another form, formB. FormB (another SimpleFormController) allows me to select a parameter to pass back to formA. This works fine in as much that if I have in FormBController.onSubmit()
{
.......
return new ModelAndView("formA", "myModel", model);
}
I am returned to formA with the correct value selected (ie the one I selected in formB) -but with formB.html in the browser url

However , when I submit formA the form is submitted to the formB controller.
How do I pass control back from FormBController to FormAController ? If I use a RedirectView I lose the the parameter and I get the class info displayed in the browser url

My mappings are:-

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/formA.html">formAController</prop>
<prop key="/formB.html">formBController</prop>
</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix"><value>/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
</beans>

irbouho
Nov 29th, 2004, 08:30 PM
If I use a RedirectView I lose the the parameter and I get the class info displayed in the browser url

I find this quite strange!!!
If you are using Spring Framework 1.1.2, try:
<bean id="formControllerB" class="...FormControllerB">
<property name="successView"><value>redirect:formA.html</value></property>
...
</bean>

HTH

mikehalfsheen
Nov 30th, 2004, 04:09 AM
Thanks. What I was doing was :-
formA ->formA
in FormBController.onSubmit () I was creating a FormABean and setting the parameter chosen from formB. I was doing

String name = formB.getName();
FormABean formABean = new FormABean();
formABean.setName(name);

return new ModelAndView("formA", "formABean",formABean);

This worked fine except, as I said when I submitted formA it went to FormBController. If I Redirected the view I lost the FormABean.


However if I just returned the parameter chosen in formB to formA using a RedirectView I am able to pull the parameter from the request in FormAController.formBackingObject
eg

in FormB.onSubmit()

return new ModelAndView(new RedirectView("formA.html"), "name",formB.getName());

in FormAController..
protected Object formBackingObject(HttpServletRequest request) throws ServletException {

String name = request.getParameter("name");
FormABean formABean= new FormABean();
if(name != null){
formABean.setName(name);
}
return formABean;

}

I

klr8
Nov 30th, 2004, 07:04 AM
If you have situations where more complex data (e.g. a Java object) needs to be exchanged between 2 controllers of your application, take a look at Spring Web Flows: http://www.ervacon.com/products/springwebflow/article.

Erwin

stueccles
Nov 30th, 2004, 07:29 AM
how about setting formA to use a session form? so the object is stored in the session and can be retrieved after form B.

mikehalfsheen
Nov 30th, 2004, 09:59 AM
Thanks for the links and tips. Very useful, I'll off to inwardly digest :)