AlanObject
AlanObject

Reputation: 9943

How to get p:resetInput functionality on p:ajax-submitted input component

I have a text field and a validator as shown below. It uses p:ajax to submit the value the moment it is changed, and the validator stops the submission if the field does not pass. The user gets the error message as expected (which is what update="msgs .." does).

However when it doesn't pass I want to reset the value to what it was before.

                                <p:inputText id="txtName"
                                             value="#{workspace.selectedPath.name}"
                                             style="width: 20%"
                                             validator="validateName"
                                             valueChangeListener="#{workspace.doNameChanged}"
                                             >
                                    <p:ajax update="msgs formTree" />
                                </p:inputText>

The following link shows how to use the p:resetInput tag in PrimeFaces, but it doesn't work as part of p:inputText because it is not an ActionSource. If you make it a child of the p:ajax tag it is just ignored. Any suggestions?

How to reset input fields in a form after validation fail when updating it with new values

Upvotes: 2

Views: 2740

Answers (1)

BalusC
BalusC

Reputation: 1108632

Since PrimeFaces 4.0, you can use <p:ajax resetValues> for this.

<p:inputText ...>
    <p:ajax ... resetValues="true" />
</p:inputText>

See also:

Upvotes: 2

Related Questions