wood burning stoves 2.0*
The moose likes JSF and the fly likes Double submit issue using JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Double submit issue using JSF" Watch "Double submit issue using JSF" New topic
Author

Double submit issue using JSF

Marcelo Tataje
Ranch Hand

Joined: Jan 31, 2011
Posts: 64

I hope somebody could help me with this issue, it's the first time I'm working with JSF after working for three years with Struts2. I need a functionality in JSF to handle double submit on an xhtml page. I mean I have a h:commandButton hich executes an action which registers a group of entities in a database and send an email after this, all this is done, but since it takes some time to perform the operation, the user can click again the submit button, that's why I need to avoid the second click, is there any idea for this?
I tried with a javascript that disables the button for some seconds but I don't know if it's 100% effective and if it's correct to do that in a formal application. I head about seam and shale frameworks but when I look for shale it's not available anymore and seam is for JBoss and I'm working with Apache Tomcat.

I'll be grateful if somebody could help me with this please, thanks in advance.
Sachin Yewale
Greenhorn

Joined: Feb 02, 2012
Posts: 21
try to use javascript function to submit form after click on h:commandAction button or atleast call a javascript function that will disable the button.
Marcelo Tataje
Ranch Hand

Joined: Jan 31, 2011
Posts: 64

Thanks, but as I menctioned before, I've already tried with javascript, but I don't know if it's 100% effective, since even when I disable the button I can click again the button and send the request for the second time. I know there are some frameworks which that can be integrated to use something like s:token, but I'm not sure if it's compatible with Tomcat using JSF. Is there any other possible solution or implementation for this?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

I wouldn't trust any client-side code to be 100% secure against a double submit, although you can probably do a pretty reasonable approximation by coding an "onsubmit" attribute that disables the control and returns true (if you return false, you'll disable the control and NOT submit!). Also code up a dblclick attribute, but be warned: in my experience double-click handlers in JavaScript can behave in inconsistent ways depending on the browser being used.

On the server side, I would generally attach some sort of unique identifying token to the data. A transaction ID is always useful, if available. I then interlock at the database transaction level. So a double-submit can happen, but the second attempt to update the database would bounce.

Which leads us to the final part of the triad. If they DO manage to double-submit and they DO bounce, you ideally want to not display the bounce as a error to the client as long as the original transaction was a success.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Double submit issue using JSF
 
Similar Threads
Seam - double submit
Add Rows Functionality in JSF
RichFaces + Seam configuration
Seam+RichFaces configuration
what could be the better way of saving data using jsf