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?
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.
When I want to update something after change in selectOneMenu, I use <f:ajax>
tag inside selectOneMenu like this:
<h:selectOneMenu value="#{bean.selected}" >
... select items here
<f:ajax event="change" execute="@this" render="search" />
</h:selectOneMenu>
Where search is the Id
of the object you want to update.
Other solution is that you should try onchange
not onChange
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With