Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double submit issue using JSF

 
Marcelo Tataje
Ranch Hand
Posts: 64
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic