Reputation: 8151
In the following code I'm disabling the Command-Button by default and enabling after any change in the Input.
Button is enabling fine but,
Action method [reconfirmAction()] of the button is not called when the button is Enabled, using Client Side API method
button_widget.enable()
Here is the code:
<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 using Primeface 3.5 and Mojarra 2.1.13
Upvotes: 0
Views: 1403
Reputation: 1885
You need to enable the button using JSF not 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;
}
You can listen on the change in the inputfield with Ajax:
<h:inputText value="#{myBean.userEmail}">
<p:ajax event="change" listener="#{bean.enableButton}" update="testbutton"/>
</h:inputText>
Also make sure that the bean is at least @ViewScoped
Upvotes: 3