How to do double-click prevention in JSF

前端 未结 7 1110
生来不讨喜
生来不讨喜 2020-11-29 02:56

We have a few search pages that run against a lot of data and take a while to complete. When a user clicks on the search button, we\'d like to not allow them to submit the s

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 03:31

    None of alternatives above has worked for me (I've really tried each one of them). My form was always sent twice when user double-clicked the login button. I'm working with JSF (Mojarra 2.1.6) on Glassfish 3.1.2.

    Consider that it was a non-AJAX login page.

    So here's the way I solved it:

    1. define a global JavaScript var to control submition in the page header or anywhere outside your form:
    var submitting = false;
    
    1. set it to true when submit h:form onsubmit event is fired:
    
    
    1. Check the var's value on h:commandLink's click event:
    
    

    This is just another simple alternative and it was tested in Chrome [Version 47.0.2526.106 (64-bit)], Mozilla Firefox (37.0.2) and Internet Explorer 11. I hope it helps someone.

提交回复
热议问题