I need to call an ajax update after changing the text field, which is the <p:autoComplete> component. I noticed that if the user prefers to enter text manually, the event is a change, whereas if the user clicks on one of the suggestions for autocompletion, the event is itemSelect. Therefore, I added two <p:ajax> children to the input, each of which calls the same method and has the same list of updates, but one has event="change" and the other event="itemSelect" .
However, now I am discovering something strange. For example, in normal server mode, I opened my page and typed "12". Autofill suggested "1233" and "1234" as suggestions. I hit 1233 and nothing seemed to happen. I clicked again and everything else filled.
Repeat this in the debugger with a breakpoint in the event handler, and I see that after the first click the value is "12", and the second time it becomes "1233".
By switching the comments of two different <p:ajax> , I see different consequences. Without a "change", a handler is never called if the user selects an autocomplete sentence, and without "itemSelect", one handler is never called if the user types manually. But with both of them there are two challenges, and I'm sure there will be complaints about a double click.
Some pseudo codes for those who like, first xhtml:
<p:autoComplete id="itemId" value="#{myBacker.myBean.itemNumber}" required="true" completeMethod="#{myBacker.idAutoComplete}"> <p:ajax event="itemSelect" update="beanDetails" listener="#{myBacker.idChangeEventListener()}" /> <p:ajax event="change" update="beanDetails" listener="#{myBacker.idChangeEventListener()}" /> </p:autoComplete> <h:panelGroup id="beanDetails"> <h:panelGroup rendered="#{not empty myBacker.myBean.institutionName}"> <h:outputText value="#{myBacker.myBean.institutionName}" /> </h:panelGroup> </h:panelGroup>
Then the Java bean support code:
public void idChangeEventListener() { myBean = myDAO.getDetails(myBean);