How does your MVC framework handle duplicate posts?
One of the problems that you'll often see in webapps is that when a record is added - hitting refresh on the browser will cause a 2nd record to be added. This is because the "Save" action usually does a forward, rather than a redirect, and the full post is re-created. I'm curious to know how other MVC Frameworks handle this issue, particularly Spring, WebWork, Tapestry and JSF. In Struts, it's pretty simple to solve. When the form is first displayed, you'll likely go through an Action. In AppFuse, this would be something like UserAction.edit(). In the edit method, you add a saveToken() call to put a token into the session:
// edit method - mark start of operation
|
Then in the save() method, you can check for a duplicate post using the isTokenValid() method:
// save method - check for valid token
|
How does your Java MVC framework handle this? Do you have to programmatically handle it like Struts - or is it built-in to the framework to handle it auto-magically?
Posted by Daniel Sheppard on April 21, 2004 at 05:45 AM MDT #
Posted by jimmy on April 21, 2004 at 06:03 AM MDT #
Posted by Drew McAuliffe on April 21, 2004 at 07:30 AM MDT #
Posted by Matt Ho on April 21, 2004 at 08:18 AM MDT #
In WebWork2, you have two options for dealing with duplicate submissions. One option is to catch the invalid token and redirect the user to another page (like your example) by doing the following:
1. include then token tag in your HTML form
<ww:token name="'myToken'"/>
2. drop the TokenInterceptor onto your action (or the default stack). it's already predefined as 'token'. Here's an example ... the line with "token" is all that would need to be added.
3. add a named result called, invalid.token, that will deal with duplicate submission.
That's it!
The alternate approach is to "redo" the action using returns cached from the previous execution. The only difference in implementation is to replace the "token" interceptor with the "token-session" interceptor and remove the invalid.token named result.
With the second approach, if the user hits reload on the payment page:
Posted by Matt Ho on April 21, 2004 at 08:23 AM MDT #
Posted by Chris May on April 21, 2004 at 08:26 AM MDT #
Posted by Matt P. on April 21, 2004 at 12:53 PM MDT #
Posted by Wolfgang Wopperer on April 21, 2004 at 03:22 PM MDT #
How does you framework handle success messages? Do you have convenience methods to set them and taglibs to grab them?
Posted by Matt Raible on April 21, 2004 at 04:03 PM MDT #
Posted by rich! on April 21, 2004 at 04:07 PM MDT #
The element to added to a navigation case is .
Posted by Wolfgang Wopperer on April 21, 2004 at 05:01 PM MDT #
Posted by Jason Carreira on April 21, 2004 at 05:44 PM MDT #
Posted by Jason Carreira on April 21, 2004 at 05:47 PM MDT #
In our home built discussion form we have duplicate submissions to the forum about 10% of the time. I suspect this is due to user's refreshing a page after a submit. (although it might be from a double-click on the button). I've been meaning to fix this; I'll probably use a method similar to what you mentioned.
Posted by Will on April 21, 2004 at 07:25 PM MDT #
Posted by Ugo Cei on April 21, 2004 at 08:01 PM MDT #
Posted by Unknown on April 21, 2004 at 09:44 PM MDT #
Posted by Sandy McArthur on April 21, 2004 at 10:16 PM MDT #
Posted by Jason Carreira on April 21, 2004 at 10:20 PM MDT #
Posted by Daniel Sheppard on April 22, 2004 at 12:51 AM MDT #
Posted by Jason Carreira on April 22, 2004 at 01:55 AM MDT #
Posted by Rajesh Patel on September 01, 2004 at 03:03 PM MDT #
Posted by Hans Sponberg on October 25, 2004 at 09:55 PM MDT #