That depends on how you're submitting the form. If you're using
or any other Ajax based tag to perform the submit by Ajax, then your best bet is to use jsf.ajax.addOnEvent()
to add a function which disables the button when the Ajax request is about to be sent and re-enables it after the Ajax response is retrieved.
E.g. as follows, which you include after the JSF Ajax scripts are included, e.g. inside a <script>
or
referring a .js
file in
.
jsf.ajax.addOnEvent(function(data) {
if (data.source.type != "submit") {
return;//Ignore anything else than input type="submit".
}
switch (data.status) {
case "begin":
data.source.disabled = true;//Disable input type="submit".
break;
case "complete":
data.source.disabled = false;//Re-enable input type="submit".
break;
}
});
送信を実行するためにAjaxを使用していない場合は、 onclick
に setTimeout()
関数をスローする方法があります。クリックしてから数ms後にボタンを無効にします。
基本的に、
すぐに無効にすると、ボタンの name = value
のペアがJSFの原因となるリクエストとともに送信されないため、 setTimeout()
は必須です実行されるアクション
を特定できません。もちろん、それをいくつかのDOM準備またはウィンドウのロード機能にリファクタリングすることができます。これは、すべての送信ボタンにこれを適用します(jQueryはこれに非常に役立ちます)。