<f:ajax> doesn't work on PrimeFaces component

ajax, events, jsf, primefaces

Solution

First of all, `onChange` is the wrong event name. It's `change`. Secondly, if you intend to call the HTML attribute name, `onChange` is also the wrong attribute name. It's `onchange`.

Coming back to your concrete problem; the standard JSF `<f:ajax>` is not compatible with PrimeFaces components. You should be using PrimeFaces own `<p:ajax>` instead.

<p:selectOneMenu ...>
    ...
    <p:ajax listener="#{newOpProgramme.serviceChange()}" update="nomCdp" />
</p:selectOneMenu>

Note that I omitted the `event` and the `process` attributes. They both have already the right default value of `valueChange` and `@this` respectively.

See also:

- What values can I pass to the event attribute of the f:ajax tag?

- Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes

Problem

I trying to use the `onChange` event of `selectOneMenu`, but it doesn't work and the component is not displayed when I add `onChange` attribue. Can someone tell me how can I handle the `onChange` event of `<p:selectOneMenu>`? Here is my view: ``` <p:selectOneMenu id="service" filterMatchMode="startsWith"> <f:selectItem itemLabel="Selectionner un Service : " /> <f:selectItems value="#{newOpProgramme.listeSevice}" var="service" itemValue="#{service.serviceId}" itemLabel="#{service.serviceNom}"/> <f:ajax event="change" execute="@this" listener="#{newOpProgramme.serviceChange()}" render="nomCdp"/> </p:selectOneMenu> ``` And here is the `<f:ajax listener>` method in a request scoped bean: ``` public void serviceChange() { System.out.println("change"); } ``` When I change the menu, however, nothing is been printed. How is this caused and how can I solve it?

Original source

Related problems