Hi All,
As i am new to JSF-Primefaces , I was trying to make two drop down. first is for the country and on change of the country i will list cities in the next drop down. But my p;ajax action is not getting invoked.
Please find the below code snippet :
ajaxFirst.xhtml ;
<?xml version="1.0" encoding="UTF-8"?>
<!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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<h:form>
<h3>AJAX
TEST 123</h3>
<h:outputText value="Country: " />
<h:selectOneMenu id="countries" value="#{partialProcessingController.country}">
<f:selectItems value="#{partialProcessingController.country}" />
<p:ajax listener="#{partialProcessingController.handleCountryChange}" event="valueChange" process="@this"/>
<f:attribute name="item" value="#{problem}"/>
</h:selectOneMenu>
<h:outputText value="City: " />
<h:selectOneMenu id="cities" value="#{partialProcessingController.city}">
<f:selectItems value="#{partialProcessingController.city}" />
</h:selectOneMenu>
<h:outputText value="Email: " />
<h:inputText value="#{partialProcessingController.email}"
required="true" />
</h:form>
</h:body>
</html>
Bean = "partialProcessingController"
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ValueChangeEvent;
@ManagedBean(name="partialProcessingController")
@ViewScoped
public class CountryStates implements Serializable {
private List<
String> country = new ArrayList<String>();
public List<String> getCountry() {
return country;
}
public void setCountry(List<String> country) {
this.country = country;
}
public List<String> getCity() {
return city;
}
public void setCity(List<String> city) {
this.city = city;
}
private List<String> city = new ArrayList<String>();
private String email;
@PostConstruct
public void countryList(){
country.add("India");
country.add("USA");
country.add("Russia");
}
public void handleCountryChange(ValueChangeEvent event)
{
System.out.println("ppopopopopopo");
String problem = (String) event.getComponent().getAttributes().get("item");
if (problem=="India")
{
city.add("Delhi");
city.add("Agra");
city.add("J&k");
}
if (problem=="USA")
{
city.add("LA");
city.add("LV");
city.add("NY");
}
if (problem=="Russia")
{
city.add("Moscow");
city.add("NT");
city.add("listing123");
}
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
I have tried using f:ajax , still action not getting invoked. Then i tried with valueChangeListener and still the same result. Please help in this concern.