Thursday, July 05, 2012

PrimeFaces AJAX Enabled <p:selectOneMenu />

I saw a question posed on stackoverflow called Trouble with Primefaces 3.0.M2 SelectOneMenu Ajax behavior and I had just done an example a couple of months ago on a car trip so I decided to post my solution here, and reference it.

Essentially the problem is how to control the list of items in a second <p:selectOneMenu/< from the selection made in the first menu. The question comes up frequently enough that I decided to write up a demo application.

The application was developed using NetBeans 7.1.2 and PrimeFaces 3.2 originally. It has been updated to use PrimeFaces 3.3.1 which is the most current at the time of writing. I validated it on GlassFish 3.1.2.

 The Apache Maven project can be downloaded from here:

This demo wants the user to pick a state, and then a city. A key problem is not just the update, but not displaying city values if a state is not selected. Also erasing the selected city, if the state has changed.



marcin said...

I got:
at com.bluelotussoftware.example.jsf.DataBean.stateChangeListener(

I run on glassfish 3.1.2 Do you know maybe reason?
Thank you

John Yeary said...
This comment has been removed by the author.
John Yeary said...

Interestingly... the exception is being caused by the valueChangeListener="#{dataBean.stateChangeListener(event)}". If you remove the (event), it will start working.

marcin said...

Thank you:)

aditya shanker tagirisa said...

thank you soo much man your code helped me a lot _/\_

Popular Posts