• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Double submit issue using JSF

 
Ranch Hand
Posts: 64
Oracle Java 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.
 
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
Oracle Java 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?
 
Saloon Keeper
Posts: 22628
153
Android Eclipse IDE Tomcat Server Redhat Java 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.
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic