<p:commandButton>当禁用=“真"时不工作原来 [英] <p:commandButton> not working when disable="true" initially

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

问题描述

这是我的 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 并且按钮被禁用了.但是,当我将 lackButton 的 disable 属性设置为 true 时,该按钮不再起作用:

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();" />

当我单击第二个按钮时,我看到 Drink water 并且启用了第一个按钮.但是,当我点击第一个按钮时,没有任何反应.

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.

推荐答案

rendered 属性一样,JSF 在处理过程中重新评估服务器端的 disabled 属性表单提交作为防止篡改请求等的一部分.但是,您可以通过 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.

您需要确保 disabled 属性的值在请求期间评估 false 每当您打算在处理表单提交期间启用按钮时.例如,将其绑定到由另一个按钮设置的视图作用域 bean 的 boolean 属性.

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}" />

另见:

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