jsp - prevent double form submit with javascript on h:commandLink in jsf under jdk 8 -
we have jsf/tomcat/hibernate/oracle application upgrade java 8. develop using eclipse. upon upgrading java 8 (jdk 8) upgrading eclipse luna , tomcat 7.0.54 have experienced 2 issues. less serious 1 of graphical renderings have new not before. more serious issue have double form submission prevention script causing our h:commandlink components hang up. after clicking on such link, url gets appended #, , subsequent clicks on link (or other buttons on page) show our alert "already submitted - please wait..." comes our script. our script is:
// prevent double form submissions var defaultsubmit = null; var formsubmitted = false; function initform() { if (defaultsubmit == null) { defaultsubmit = document.forms[0].submit; document.forms[0].submit = submitform; document.forms[0].onsubmit = checkformsubmission; } formsubmitted = false; } function checkformsubmission() { if (formsubmitted) { alert('already submitted - please wait...'); return false; } else { formsubmitted = true; return true; } } function submitform() { if (checkformsubmission()) { if (defaultsubmit != null) { return defaultsubmit(); } } return false; } </script>
the above script part of jsp file gets included in many other jsp files within our application. worked using jdk 5, 6 , 7 has problems now. h:commandbutton's work ok, h:commandlink's cause application hang described above. how can fixed work jdk 8?
an online search use of onsubmit h:commandlink indicated onclick better choice, , allowed solution our primary problem. first, needed replace "h:commandlink ..." "h:commandlink onclick="return checkformsubmission();" ... everywhere within program. our script needed replaced new script:
var initialized = false; var formsubmitted = false; function initform() { if (initialized == false) { document.forms[0].onsubmit = checkformsubmission; initialized = true; } formsubmitted = false; } function checkformsubmission() { if (formsubmitted) { alert('already submitted - please wait...'); return false; } else { formsubmitted = true; return true; } }
when of above changes made, our double click protection once again works desired. once click made on either h:commandlink or h:commandbutton, subsequent click pops alert telling user: "already submitted - please wait...", , alert appears no matter h:commandlink or h:commandbutton subsequently pressed. our desired behavior.
Comments
Post a Comment