&LT;电话号码:&的commandButton GT;不工作时禁用= QUOT;真&QUOT;原来 [英] <p:commandButton> not working when disable="true" initially
问题描述
这是我的ManagedBean:
This is my ManagedBean:
@Named(value = "mrBean")
@RequestScoped
public class MrBean {
public void laugh() {
System.out.println("HAHAHA");
}
public void prepareToLaugh() {
System.out.println("Drink water.");
}
}
这是我的命令按钮的工作版本:
And this is the working version of my commandButton:
<p:commandButton actionListener="#{mrBean.laugh}" widgetVar="laughtButton"
value="Laugh" oncomplete="laughButton.disable();" />
当我点击上面的按钮,我看到 HAHAHA
,按钮被禁用。然而,当我设置laughButton的禁用
属性真正
,按钮不起作用了:
When I clicked the above button, I saw HAHAHA
and the button is disabled. However, when I set the laughButton's disable
attribute to true
, the button does not work anymore:
<p:commandButton actionListener="#{mrBean.laugh}" widgetVar="laughtButton"
value="Laugh" disabled="true" oncomplete="laughButton.disable();" />
<p:commandButton actionListener="#{mrBean.prepareToLaugh}"
value="Prepare to laugh" oncomplete="laughButton.enable();" />
当我点击第二个按钮,只见喝水
和第一按钮被激活。然而,当我点击一号按钮,没有任何反应。
When I click the 2nd button, I saw Drink water
and the 1st button is enabled. However, when I click on the 1st button, nothing happens.
我会非常感激,如果有人能给我我应该怎么解决这个问题的建议。我正在使用PrimeFaces 3.0 RC2。
I'd be very grateful if someone could give me an advice on how I should tackle this problem. I'm using PrimeFaces 3.0 RC2.
推荐答案
像与渲染
属性,JSF重新评估禁用
形式的处理过程中的服务器端属性提交作为对篡改请求保护的一部分,并且喜欢。但是你启用/不通知的修改服务器端通过JS将其禁用。
Like as with rendered
attribute, JSF re-evaluates the disabled
attribute in the server side during processing of the form submit as part of safeguard against tampered requests and like. You're however enabling/disabling it by JS without notifying the server side of the changes.
您需要确保在禁用
属性的计算结果假的价值
请求期间,只要你想让你的按钮的形式提交的加工过程中被激活。例如,它绑定到布尔
视图财产的范围是由另一个按钮设置的bean。
You need to ensure that the value of the disabled
attribute evaluates false
during the request whenever you intend the button to be enabled during processing of the form submit. For example, bind it to a boolean
property of a view scoped bean which is set by the other button.
<h:commandButton disabled="#{bean.laughDisabled}" />
参见:
- h:commandLink / H:的commandButton没有被调用
- h:commandLink / h:commandButton is not being invoked
See also:
这篇关于&LT;电话号码:&的commandButton GT;不工作时禁用= QUOT;真&QUOT;原来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!