<电话号码:&的commandButton GT;不工作时禁用= QUOT;真"原来 [英] <p:commandButton> not working when disable="true" initially

查看:144
本文介绍了<电话号码:&的commandButton GT;不工作时禁用= QUOT;真"原来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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没有被调用

  • See also:

    • h:commandLink / h:commandButton is not being invoked
    • 这篇关于&LT;电话号码:&的commandButton GT;不工作时禁用= QUOT;真&QUOT;原来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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