【问题标题】:p:commandButton is not calling action method after enabling the Buttonp:commandButton 在启用按钮后未调用操作方法
【发布时间】:2013-07-28 20:34:48
【问题描述】:

在以下代码中,我默认禁用命令按钮并在输入发生任何更改后启用。
按钮启用正常,但是,
按钮启用时不调用按钮的操作方法[reconfirmAction()],使用客户端API方法

button_widget.enable()

代码如下:

<h:form id="reConfirmForm">
    <h:outputLabel>User Name</h:outputLabel>
    <h:inputText value="#{myBean.userName}" onchange="btnWigetVar.enable()"/><br/>

    <h:outputLabel>Email</h:outputLabel>
    <h:inputText value="#{myBean.userEmail}" onchange="btnWigetVar.enable()"/><br/>

    <p:commandButton value="Re-Confirm" widgetVar="btnWigetVar" action="#{myBean.reconfirmAction}" disabled="true"/>
</h:form>

我正在使用 Primeface 3.5 和 Mojarra 2.1.13

【问题讨论】:

  • 最好在窗口加载时禁用&lt;p:commandButton&gt;,而不是使用disabled="true"
  • @LuiggiMendoza : 我也试过了,没用。

标签: jsf jsf-2 primefaces


【解决方案1】:

您需要使用 JSF 而不是 JavaScript 来启用按钮。

<p:commandButton id="testbutton" value="Re-Confirm" widgetVar="btnWigetVar" action="#{myBean.reconfirmAction}" disabled="#{!bean.enabled}"/>

豆子:

private boolean enabled;

public void enableButton() {
enabled = true;
}

public boolean isEnabled() {
return enabled;
}

您可以使用 Ajax 监听输入字段的变化:

 <h:inputText value="#{myBean.userEmail}">
     <p:ajax event="change" listener="#{bean.enableButton}" update="testbutton"/>
 </h:inputText>

还要确保 bean 至少是 @ViewScoped

【讨论】:

    猜你喜欢
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多