Rys
Rys

Reputation: 5164

Is posible to enable primefaces button after successful validation?

Is posible to enable primefaces button depending on the correct validation of inputText and without using jquery or writing the validation on a java class? I just looking for enable it in the view side and using several inputTexts I am trying with disabled="#{not facesContext.postback or not facesContext .validationFailed}" But maybe I am doing something wrong becouse is not working as I`m expecting. I have something like these but with 4 more inputTexts with similar code.

    <p:inputText id="user" value="#{acc.user}" 
        required="true">
        <f:validateLength ... for="user" />
        <p:ajax update="msgUser" event="keyup" />
        <p:ajax update=":#{p:component('add')}"  />
    </p:inputText>
<p:commandButton id="add" update="dataTable"
    oncomplete="addConfirm.hide()" actionListener="#{managedBean.onCreate}" 
    disabled="#{not facesContext.postback or not facesContext .validationFailed}"/>

It is all inside a confirmDialog

Upvotes: 1

Views: 1942

Answers (1)

BalusC
BalusC

Reputation: 1109865

Yes, just let the input ajax-update the button wherein you check in its disabled attribute if the current request is a postback whereby validation is failed.

<p:inputText ...>
    <p:ajax ... update="button" />
</p:inputText>
<p:commandButton id="button" ... disabled="#{not facesContext.postback or not facesContext .validationFailed}" />

Upvotes: 3

Related Questions