在JavaScript中设置disable = true后,未调用JSF h:commandButton的操作 [英] Action of JSF h:commandButton not invoked after setting disabled=true in JavaScript

查看:225
本文介绍了在JavaScript中设置disable = true后,未调用JSF h:commandButton的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁可以解释以下行为?在JavaScript中禁用命令按钮时,永远不会执行action方法.

Who can explain the following behaviour? When disabling a command button in JavaScript, the action method is never executed.

<h:form>
    <h:commandButton value="test" action="#{bean.test}" onclick="disabled=true" />
</h:form>

推荐答案

禁用HTML表单元素时,其name=value对将不会作为HTTP请求参数发送,因此JSF在请求中将永远找不到它参数图.对于命令按钮,这反过来意味着该操作永远不会被调用.

When a HTML form element is disabled, then its name=value pair won't be sent as HTTP request parameter and hence JSF will never find it in the request parameter map. For command buttons this in turn means that the action is never invoked.

您需要在提交表单后不久 禁用该按钮.提议的使用disabled属性的建议没有意义,因为为时已晚.提交表单时未设置,但仅在响应返回时设置.

You need to disable the button shortly after the form has been submitted. The proposed suggestions to use disabled attribute make no sense as it's too late. It's not set during submitting the form, but it's only set when the response returns.

要在这种特殊情况下满足特定的功能要求,可以使用JS来使禁用超时.

To achieve your particular functional requirement in this particular case, you could use JS to timeout the disablement.

<h:commandButton ... onclick="setTimeout('document.getElementById(\'' + this.id + '\').disabled=true;', 50);" />

但是使用<f:ajax onevent>

  • Pure Java/JSF implementation for double submit prevention
  • Reload parts of a page before action is executed?

这篇关于在JavaScript中设置disable = true后,未调用JSF h:commandButton的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆