admin管理员组文章数量:1304237
This is the submit button:
<h:mandButton
actionListener="#{regBean.findReg}"
action="#{regBean.navigate}" value="Search" />
This is the form:
<h:form onsubmit="this.disabled=true;busyProcess();return true;">
If the submit button is pressed, the page shows a "busy" icon until request is processed. The problem is, the form is never submitted and the request never reaches the backend. However, if I instead take out the "disabled" call like so:
<h:form onsubmit="busyProcess();return true;">
Then everything works. Any ideas?
This is the submit button:
<h:mandButton
actionListener="#{regBean.findReg}"
action="#{regBean.navigate}" value="Search" />
This is the form:
<h:form onsubmit="this.disabled=true;busyProcess();return true;">
If the submit button is pressed, the page shows a "busy" icon until request is processed. The problem is, the form is never submitted and the request never reaches the backend. However, if I instead take out the "disabled" call like so:
<h:form onsubmit="busyProcess();return true;">
Then everything works. Any ideas?
Share Improve this question edited May 18, 2010 at 0:39 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked May 17, 2010 at 20:21 MarkMark 3671 gold badge6 silver badges14 bronze badges6 Answers
Reset to default 6JSF relies on the presence of the name-value pair of the submit button to invoke a specific action in the server side. If you disable the form (at least, the button) before submitting the form, then no information will be available in the request parameter map and JSF will not invoke any action.
Your best bet is to introduce a timeout wherein you disable the button about 50ms after submitting. E.g.
onsubmit="setTimeout(function(){document.getElementById('formId:buttonId').disabled=true;},50);busyProcess();"
The explicit return true;
at end is by the way superflous. Also, disabling the the HTML form element directly ain't going to work since it doesn't have a disabled
attribute, you want to disable the button (and if necessary the other input elements as well).
Here's some improvement:
<h:form onsubmit="busyProcess(this);">
with
function busyProcess(form) {
setTimeout(function() {
for (var i = 0; i < form.elements.length; i++) {
form.elements[i].disabled = true;
}
}, 50);
// Remnant of your code here.
}
Update: since I wondered that you told that it "works", I tested the form's disabled
attribute in various browsers, it only works in MSIE (surprising..), but not in the other (real) browsers. You don't want to be browserdependent, so forget it and go ahead with disabling the form's individual elements.
Change this.disabled = true
into [buttonref].disabled = true
I'm pretty sure that disabling the whole form will mean to the browser that you don't want it to be submittable. When you disable individual input elements, those aren't included in the parameters sent to the server when the form is posted.
You've disabled the entire form, you need to disable just the button instead.
Also you will want to ensure that your busyProcess() returns a truthy value or the submission could be disabled as well.
if you want the user not to submit anything, let a layer appear above the form and remove the focus from the active ponent.
Another way would be to make sure the AJAX requests use a mon channel that has a queue in which only one request is processed at a time (easy using frameworks like prototype etc)
BalusC, your very creative timeout option works well. I actually came to the same conclusion when I tried the "disabled" attribute in other browsers. It didn't disable the form at all in Opera and Firefox. I just chalk it up to those browsers being more versatile than IE.
Sean K, disabling the button only without setting a timeout produces the same issue as the form disable, as info is passed to the server.
Thanks for all your help guys!
本文标签: javaJSF form does not get submitted when form is disabled by JavaScriptStack Overflow
版权声明:本文标题:java - JSF form does not get submitted when form is disabled by JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741783069a2397422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论