• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

F5 or page refresh calls onSubmit of spring controller - database again updated

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
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.

thank you,
Kavitha.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can generate a Unique Id and store in a hidden field in the form on the first page.
When you save the data, save this unique Id too.

Before saving, always check for presence of Unique Id, if it exists, it means this is a Re-Submit of the same information!
 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I create this field in the database and save it the first time a record is saved?
 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be good if we have some method in the controller class kind of onRefresh() which we could override and call onsubmit if necessary or just load the existing data again.
 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kavita Shivani wrote:Do I create this field in the database and save it the first time a record is saved?


Sure.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Have a look at Point 4.6 of Spring MVC Step By Step tutorial here
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should redirect after submit, so user can refresh the page without calling onSubmit again.
 
Kavita Shivani
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Cheers,
Kavita.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the update. Submit-Redirect is a pattern to specifically solve this problem.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic