FkJ FkJ - 6 months ago 73
Ajax Question

JSF 2 composite component + clientBehavior

I have a composite component that is a specialization of PrimeFaces autoComplete.

In some pages I need to use the itemSelect event, so I added

<cc:clientBehavior name="itemSelect" event="itemSelect"
targets="#{cc.attrs.id}" />


in the component interface, but the action is not fired.

What am I missing?

Component code:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui" >

<!-- INTERFACE -->
<cc:interface>
<cc:attribute name="value" required="true" />
<cc:attribute name="disabled" default="false" />
<cc:attribute name="required" default="false" />
<cc:attribute name="size" default="25" />
<cc:clientBehavior name="itemSelect" event="itemSelect"
targets="#{cc.attrs.id}" />
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation>
<p:autoComplete disabled="#{cc.attrs.disabled}"
value="#{cc.attrs.value}"
completeMethod="#{tecnicoBean.completarViajante}" var="t"
itemLabel="#{t.nome}" itemValue="#{t}" minQueryLength="2"
forceSelection="true" converter="entityConverter"
size="#{cc.attrs.size}" queryDelay="700" label="T├ęcnico:"
onclick="this.select()" cache="true">
</p:autoComplete>
</cc:implementation>
</html>


Component usage:

<ezcomp:tecnicos value="#{sessionScope.tecnicoRdv}">
<p:ajax event="itemSelect" process="@this" update=":mainPanel"
listener="#{rdvBean.changeTecnico}" />
</ezcomp:tecnicos>

FkJ FkJ
Answer

Finally got it working.

I had to add id="#{cc.attrs.id}" to the p:autoComplete component.