简体   繁体   English

jsf + jquery:通过JQuery禁用和启用h:commandButton

[英]jsf + jquery: disable and enable h:commandButton by JQuery

I have a jsf form with h:commandButton as submit button: 我有一个h:commandButton作为提交按钮的jsf表单:

<h:form>
     <h:commandButton id="import_opener" binding="#{submit}" disabled="true" action="#{bean.save}" value="submit"/>
</h:form>

and I try to set "disabled" attribute to true (to enable the button) by JQuery: 并且我尝试通过JQuery将“ disabled”属性设置为true(以启用按钮):

$("[id='#{submit.clientId}']").prop("disabled", false);

and everything works fine. 一切正常。 But when I submit commandButton the action #{bean.save} doesn't fire, just reloads the form page. 但是,当我提交commandButton时,动作#{bean.save}不会触发,只是重新加载表单页面。 If I do not operate on the h:commandButton by JQuery the action is fire. 如果我没有通过JQuery在h:commandButton上进行操作,则操作将被触发。

Please, help me to run #{bean.save} after JQuery has changed the disable attribute of h:commandButton. 请帮助我在JQuery更改h:commandButton的disable属性后运行#{bean.save}。

This is because JSF has some built-in security features. 这是因为JSF具有一些内置的安全功能。 The incoming request is checked if it is "possible" or not. 检查传入的请求是否“可能”。 The incoming request tells JSF that a button, which actually was disabled has been pressed. 传入的请求告诉JSF已经按下了实际上被禁用的按钮。 So the request will be handled as invalid and kind of refused. 因此,该请求将被视为无效且被拒绝。 This is good because the browser can be manipulated in many ways. 这很好,因为可以通过多种方式来操纵浏览器。

The solution is to not set disabled="true" , but let it enabled on the JSF side and disable it via jQuery, instead of the other way around. 解决方案是不设置disabled="true" ,而是让它在JSF端启用并通过jQuery禁用它,而不是相反。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM