• Post Reply Bookmark Topic Watch Topic
  • New Topic

p:selectOneMenu is not working  RSS feed

prasad neena
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your codes here, so that we can find out what is the problem?
prasad neena
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"

<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="#{app.country}" style="color:black" ></hutputLabel>
<p:inputText value="#{customerBean.country}"></p:inputText>

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

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

<hutputLabel value="city" style="color:black" ></hutputLabel>
<p:selectOneMenu id="city" value="#{listBean.city}">
<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.io.Serializable;
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) {
this.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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Here is the code

<managed-bean-class>com.mq.updatemanager.web.supportmanager.customermangement.PPRBean </managed-bean-class>


Then also its not working.
Siew Ling
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!