Charbel Abdul-Massih wrote:
What’s the best way to handle double clicks on buttons in JSF???
If your application only uses request-scope beans, then I suggest just allowing the double clicks; two requests will be sent and processed. The user receives the output of the last one. This does allow a user to "change their mind", ie click on button 1, then click on button 2; they get the result of button 2. This is the way the web "normally" works.
If the server uses session-scope stuff then of course this just cannot be allowed; a second request can fail due to changes caused by the first request.
The project I'm currently working on uses javascript in every page to override the onsubmit method of every form to set a flag in the form. If the flag is true, the onsubmit returns false, ensuring that a form can only be submitted once.
Of course there should be a server-side check too (eg using the token tag from Shale) but I think using javascript to disable stuff provides a nicer client-side experience than redirecting the user to an error page if they click too often.
Regards, Simon

