Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf p:commandButton在启用按钮后未调用操作方法_Jsf_Jsf 2_Primefaces - Fatal编程技术网

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:我也试过了,但没用。