Pen capture <p: autoComplete> event change (emptying detection)
I have a question about Primefaces autocomplete. Now I am updating the field with the property value of the selected value in autocomplete, for example:
This is in my xhtml:
<p:autoComplete value="#{trFitoModel.selectedProducte}" id="nomComercial" completeMethod="#{trFitoBacking.completeProducte}" var="producte" itemLabel="#{producte.nom}" itemValue="#{producte}" converter="#{ProducteFitoConverter}" forceSelection="true" onkeyup="this.value = this.value.toUpperCase();"> <p:ajax event="itemSelect" listener="#{trFitoBacking.handleSelect}" update="text" global="false" /> <f:validator validatorId="qea.validators.EmptyFieldValidator" /> <f:attribute name="validationTitle" value=" NomComercial " /> </p:autoComplete> </p:column> <p:column> <h:outputLabel>#{msgI18N.trFito}</h:outputLabel> <h:outputText id="text" value="#{traFitoBacking.resgistre}"> </h:outputText> </p:column> And this is my Bean support:
public void handleSelect(SelectEvent event) { ProducteFitosanitari p=(ProducteFitosanitari)event.getObject(); setResgistre(Integer.toString(p.getNumRegistre())); } This works, but now I'm trying to update the outputText with the identifier "text" with an empty string when the autocomplete value is empty.
How can I capture the event p:autoComplete when p:autoComplete ?
The autoComplete binding generates 2 events: "change" and "itemSelect", for 2 methods of changing its contents: input or selection from the drop-down list. So you need to register 2 p:ajax listeners:
<p:autoComplete ... > <p:ajax event="itemSelect" listener="#{bean.action}" process="@form"/> <p:ajax event="change" listener="#{bean.action}" process="@form"/> </p:autoComplete> You will need the signature of the 2nd server:
public void action(AjaxBehaviorEvent event) to record the change event.
Instead of event you can use the onstart attribute with JavaScript to run ... You will find additional parameters for p:ajax in the "User Manual" section, "AjaxBehavior" section.