Jsf p:commandButton在启用按钮后未调用操作方法
在下面的代码中,我默认禁用命令按钮,并在输入发生任何更改后启用。Jsf p:commandButton在启用按钮后未调用操作方法,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,在下面的代码中,我默认禁用命令按钮,并在输入发生任何更改后启用。 按钮处于启用状态,但, 启用按钮时,使用客户端API方法不会调用按钮的操作方法[重新确认操作()] button_widget.enable() 代码如下: <h:form id="reConfirmForm"> <h:outputLabel>User Name</h:outputLabel> <h:inputText value="#{myBean.userName}"
按钮处于启用状态,但,
启用按钮时,使用客户端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}"/>
您可以使用Ajax监听inputfield中的更改:
<h:inputText value="#{myBean.userEmail}">
<p:ajax event="change" listener="#{bean.enableButton}" update="testbutton"/>
</h:inputText>
还要确保bean至少是@viewscope的您需要使用JSF而不是JavaScript来启用按钮
<p:commandButton id="testbutton" value="Re-Confirm" widgetVar="btnWigetVar" action="#{myBean.reconfirmAction}" disabled="#{!bean.enabled}"/>
您可以使用Ajax监听inputfield中的更改:
<h:inputText value="#{myBean.userEmail}">
<p:ajax event="change" listener="#{bean.enableButton}" update="testbutton"/>
</h:inputText>
还要确保bean至少是@viewscope在窗口加载上禁用
会比使用disabled=“true”
@luigimendoza:我也试过了,但它不起作用。在窗口加载上禁用
会比使用disabled=“true”更好
@LuiggiMendoza:我也试过了,但没用。