I do a form submit in my first page, the form data is saved and returned in the next page as a result set. Now when I refresh the second page, the data is again saved in the database from the previous page. I could see that the onSubmit of the first page controller is being called again. How do I stop this. Because I already saved the data and I also have the result set in my command object on refresh i simply want to display the existing values.
You should redirect after submit, so user can refresh the page without calling onSubmit again.
SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Joined: Aug 14, 2009
Ok that worked great for me. Since its a dumb page after form submission, I dint have much to do, I did a redirect, and in the next page's controller I have overridden referenceData() method of the spring's SimpleFormController class which gets called repeatedly (no additonal code necessary here for this to work) but to let you know that this gets called on every refresh. I make sure I send the request attibutes that I need in my next page at the end of the onsubmit. And its working fine.
To help anyone who will search for this in future I have placed my code snippet.
In my page one on form submit:
In my page 2 do nothing, just F5 and you still have old data and no submit action takes place for the old page.
Thank you, everyone for your response and suggestion.
Joined: Jul 05, 2005
Thanks for the update. Submit-Redirect is a pattern to specifically solve this problem.