'PrimeFaces ajax change of input and action on another field

I have this code, where, on change of value of an input element, I listen and update some other fields.

The problem is, when I change the value of this input field by typing something and hit the commandButton with the id: submit, it triggers the listener (probably because the change of value is checked during the blur on the field), but not the listener X, i.e the actionListener for the commandButton. So I've had to click the button again for the listener X to be invoked.

Of course it works as expected if I cause a blur on the input field by clicking elsewhere and then click on the commandButton. It appears like when the blur of the input field coincided with the click of the commandButton, only the blur happens - the click of the button is simply ignored. Any ideas?

<p:inputText ...>
  <p:ajax event="change" update="..." listener="..." />
</p:inputText>

...

<p:commandButton id="submit" ... actionListener="X" />

EDIT: I use PrimeFaces v5.1 and JSF v2.1.19, FWIW.



Solution 1:[1]

I had a similar issue (maybe exactly the same) using JSF and PrimeFaces 6.1, and posted it here:

PrimeFaces inputText ajax event=valueChange fires AFTER commandButton clicked

@jasper-de-vries replied with a valid, working solution :)

a quickie summary of his post is to change the ajax update into a seletor as such:

<p:ajax update="@(form :input:not(button))" />

which will update specific elements (the form) but not others (buttons) since the valueChange or change event updates all the form including buttons which then disregards the first click on the button.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community