Trouble with Primefaces 3.0.M2 SelectOneMenu Ajax behavior Trouble with Primefaces 3.0.M2 SelectOneMenu Ajax behavior ajax ajax

Trouble with Primefaces 3.0.M2 SelectOneMenu Ajax behavior


I created a demo for the exact same situation you describe in your project. I have a state and city <p:selectOneMenu/> elements on my page. You select a state, and the cities update. If a different state is selected, the city is erased since it may not exist in the state.

The difference is that I use <p:ajax event="change" update="cities, cs"/> to update the elements, and an actionListener to update the city if the state is different.

<p:selectOneMenu id="states" value="#{dataBean.selectedState}"   valueChangeListener="#{dataBean.stateChangeListener(event)}"   style="width: 150px;">   <f:selectItem itemLabel="" itemValue=""/>   <f:selectItems value="#{dataBean.states}"/>   <p:ajax event="change" update="cities, cs"/></p:selectOneMenu><h:outputLabel value="City:" for="cities"/><p:selectOneMenu id="cities"    value="#{dataBean.selectedCity}"    style="width: 150px;">   <f:selectItem itemLabel="" itemValue=""/>   <f:selectItems value="#{dataBean.cities}"/>   <p:ajax event="change" update="cs" /> </p:selectOneMenu>

The whole project and demo code can be found on my blog. I saw this post and decided to post my project. [blog]: http://javaevangelist.blogspot.com/2012/07/primefaces-ajax-enabled.html


Primefaces is trying something diffent. I dont know why. First of all you must know these releases are not stable.When you analys code with firebug you will shove this.Lets assume two combo who has ids countries and citieswhen you changed the first combo cities update correcty but cities combo' id change to cities_input they add _input prefix. When I analys primefaces source code. Thereare codes something like traverse tree if visited change id by adding _input or _panel. So if you change the combo in second time. Everything work perfect except you said update cities but there is no component who has id cities becouse it has new id cities_input. So your ajax does not work correctly. But they correct this bug in 3.0m4 or after releases.

This is the problem. Another example of this problem it is bug someone open jira for this.İf you are using login with spring security j_username, j_password change to j_username_input j_password_input. So this breaks the standart and code does not work in second ajax requests.Hope this helps..

pay attention to lionhearts words. Primefaces namespaces changed in 3.m4 in pages use this.xmlns:p="http://primefaces.org/ui"


I did a state -> city select in my jsf project the same way you did. The only differences I found are:

  • my p:ajax has a change event: <p:ajax event="change" update="city" listener="#{contatoMB.filterCities}" />.
  • my p:ajax comes last after the f:selectItems but this shouldn't be the problem.
  • my f:selectItems list in the city select is List<javax.faces.model.SelectItem> and not a Map<String, City>, have you tried using SelectItems instead of your map?
  • my form has an id and prependId false <h:form id="contact-form" prependId="false">, again, this shouldn't be the problem.
  • my h:selectOneMenu is inside a p:panel, some PrimeFaces components behave in a strange way when inside or outside some other components.

If none of this works maybe the problem is the PrimeFaces version you're using. My PrimeFaces version is 2.2.1.