File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes p:selectOneMenu is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "p:selectOneMenu is not working " Watch "p:selectOneMenu is not working " New topic

p:selectOneMenu is not working

prasad neena

Joined: Jan 03, 2013
Posts: 11

p:selectOneMenu is not working .I would like to display countries ,states,and cities information by using p:selectOneMenu. But I cant make it workable...As It is working with h:selectOneMenu.

Any help greatly appreciated.
Siew Ling

Joined: Jan 08, 2013
Posts: 6
Can you post your codes here, so that we can find out what is the problem?
prasad neena

Joined: Jan 03, 2013
Posts: 11

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns=""

<ui:composition template="/pages/templates/layout.xhtml">
<ui:define name="body">
<div class="widget" align="center">
<font style="font-weight: bold;" color="#005A96">Customer Details</font>
<h:panelGrid columns="2" cellspacing="9">

<hutputLabel style="color:black" value="#{app.productName}" ></hutputLabel>
<p:inputText value="#{customerBean.productName}"></p:inputText>

<hutputLabel value="#{app.customerName}" style="color:black" ></hutputLabel>
<p:inputText value="#{customerBean.customerName}"></p:inputText>

<hutputLabel value="#{app.contactPerson}" style="color:black" ></hutputLabel>
<p:inputText value="#{customerBean.contactPerson}"></p:inputText>

<hutputLabel value="#{app.landLineNumber}" style="color:black" ></hutputLabel>
<p:inputText value="#{customerBean.landLineNumber}"></p:inputText>

<hutputLabel value="#{app.mobileNumber}" style="color:black" ></hutputLabel>
<p:inputText value="#{customerBean.mobileNumber}"></p:inputText>

<hutputLabel value="#{app.emailId}" style="color:black" ></hutputLabel>
<p:inputText value="#{customerBean.emailId}"></p:inputText>

<hutputLabel value="#{}" style="color:black" ></hutputLabel>
<p:inputText value="#{}"></p:inputText>

<hutputLabel value="#{app.state}" style="color:black" ></hutputLabel>
<p:inputText value="#{customerBean.state}"></p:inputText>

<hutputLabel value="#{}" style="color:black" ></hutputLabel>
<p:inputText value="#{}"></p:inputText>

<hutputLabel value="city" style="color:black" ></hutputLabel>
<p:selectOneMenu id="city" value="#{}">
<f:selectItem itemLabel="Select City" itemValue="" />
<f:selectItems value="#{listBean.cities}" />
<p:ajax update="suburbs" listener="#{listBean.handleCityChange}" />

<hutputLabel value="state" style="color:black" ></hutputLabel>
<p:selectOneMenu id="suburbs" value="#{listBean.suburb}">
<f:selectItem itemLabel="Select Suburb" itemValue="" />
<f:selectItems value="#{listBean.suburbs}" />

<hutputLabel value="" ></hutputLabel>
<p:panelGrid columns="3"></p:panelGrid>
<hutputLabel value=""></hutputLabel>

<h:panelGrid columns="3" cellspacing="2">

<p:commandButton value="Next"
action="#{customerBean.customerDetails1}" styleClass="button1"></p:commandButton>
<p:commandButton type="reset" value="Reset"




package org.primefaces.examples.view;

import java.util.HashMap;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

public class PPRBean implements Serializable {

private String city;

private String suburb;

private Map<String,String> cities = new HashMap<String, String>();

private Map<String,Map<String,String>> suburbsData = new HashMap<String, Map<String,String>>();

private Map<String,String> suburbs = new HashMap<String, String>();

public PPRBean() {
cities.put("Istanbul", "Istanbul");
cities.put("Ankara", "Ankara");
cities.put("Izmir", "Izmir");

Map<String,String> suburbsIstanbul = new HashMap<String, String>();
suburbsIstanbul.put("Kadikoy", "Kadikoy");
suburbsIstanbul.put("Levent", "Levent");
suburbsIstanbul.put("Cengelkoy", "Cengelkoy");

Map<String,String> suburbsAnkara = new HashMap<String, String>();
suburbsAnkara.put("Kecioren", "Kecioren");
suburbsAnkara.put("Cankaya", "Cankaya");
suburbsAnkara.put("Yenimahalle", "Yenimahalle");

Map<String,String> suburbsIzmir = new HashMap<String, String>();
suburbsIzmir.put("Cesme", "Cesme");
suburbsIzmir.put("Gumuldur", "Gumuldur");
suburbsIzmir.put("Foca", "Foca");

suburbsData.put("Istanbul", suburbsIstanbul);
suburbsData.put("Ankara", suburbsAnkara);
suburbsData.put("Izmir", suburbsIzmir);

public String getCity() {
return city;

public void setCity(String city) { = city;

public String getSuburb() {
return suburb;

public void setSuburb(String suburb) {
this.suburb = suburb;

public Map<String, String> getCities() {
return cities;

public void setCities(Map<String, String> cities) {
this.cities = cities;

public Map<String, Map<String, String>> getSuburbsData() {
return suburbsData;

public void setSuburbsData(Map<String, Map<String, String>> suburbsData) {
this.suburbsData = suburbsData;

public Map<String, String> getSuburbs() {
return suburbs;

public void setSuburbs(Map<String, String> suburbs) {
this.suburbs = suburbs;

public void handleCityChange() {
if(city !=null && !city.equals(""))
suburbs = suburbsData.get(city);
suburbs = new HashMap<String, String>();

public void displayLocation() {
FacesMessage msg = new FacesMessage("Selected", "City:" + city + ", Suburb: " + suburb);

FacesContext.getCurrentInstance().addMessage(null, msg);
Siew Ling

Joined: Jan 08, 2013
Posts: 6
You copy the codes from the primefaces showcase and added your codes in.
What I see from here is you have added codes in your jsf page which it needs to have app managed bean and customerBean managed bean.

Besides that your PPRBean does not have the annotation for
@ManagedBean (name="listBean")
or have you define your managed bean in the faces-config.xml?

You can have a look in this tutorial for configuring managed bean

and look at this example for using managed bean in jsf

Hope this help.
prasad neena

Joined: Jan 03, 2013
Posts: 11

Hi..I was added managed bean entry into faces-config.xml file..

Here is the code

<managed-bean-class> </managed-bean-class>


Then also its not working.
Siew Ling

Joined: Jan 08, 2013
Posts: 6
You will need to add 2 managed bean class for your following codes, which is App class and CustomerBean class.

For example:

The above is just an example, you will need to complete the others.

Then add these 2 managed bean in your faces-config.xml
I agree. Here's the link:
subject: p:selectOneMenu is not working
It's not a secret anymore!