PDA

View Full Version : Duplicate form submission when using form bean as an instance variable in controller


yasser
May 2nd, 2008, 08:36 PM
hello,

I am stuck up with a weird problem.

Problem: The form gets submitted twice, when using the form bean as an instance variable to the controller.

Description:
I am using MultiActionController and there are a few objects that I have to keep in session, so I chose to inject the form bean as an instance variable in the controller. I have overridden the newCommandObject method, which will return the instance variable.
When I click on the submit button the first time, the form gets submitted fine.
The next time I click submit, the form gets submitted twice.
Every alternate click produces "2 form submission".

There are 4 submit buttons in the screen. Regardless of what button I click, duplicate form submission occurs.

Help: Please let me if I am doing the right thing by injecting the bean as an instance variable. If not, is there a way I can keep the form (with object attribute values ) in session ?

I am using spring 1.2, so can't use scoped beans.

Here is code extract



Controller:
public class XController extends MultiActionController
{
private ApplicationSummaryBean applicationSummaryBean;

protected Object newCommandObject(Class arg0) throws Exception
{
if(applicationSummaryBean.getSomeList() == null)
{
applicationSummaryBean.setSomeList(service.getBusi nessList());
}
return applicationSummaryBean;
}

public ModelAndView submitApplication(HttpServletRequest request,
HttpServletResponse response, ApplicationSummaryBean command)
{
System.out.println("in submit");
..........some processing
return modelAndView;
}

public ModelAndView otherMethods(HttpServletRequest request,
HttpServletResponse response, ApplicationSummaryBean command)
{
return modelAndView;
}
}

config.xml
<bean id="xcontroller"
class="com.xxx.xxxx.xController">
<property name="methodNameResolver"
ref="xmethodNameResolver" />

<property name="applicationSummaryBean"
ref="applicationSummary" />
</bean>
<bean id="applicationSummary"
class="xxx.xxxx.ApplicationSummaryBean"
singleton="false">

yasser
May 6th, 2008, 02:40 PM
please help....