p: commandButton在启用按钮后未调用操作方法



在下面的代码中,我默认禁用命令按钮,并在输入中发生任何更改后启用
按钮启用良好,但
当按钮启用时,不调用按钮的操作方法[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>

Im使用Primeface 3.5和Mojarra 2.1.13

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

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

Bean:

private boolean enabled;
public void enableButton() {
enabled = true;
}
public boolean isEnabled() {
return enabled;
}

您可以使用Ajax监听inputfield中的更改:

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

还要确保bean至少是@ViewScoped

最新更新