The city Dropdown populated when the state is selected and State Dropdown populated according Country selection; however, it is not doing this.
Problem is when country selected according country state populated in state dropdwon but after it when i select state from state dropdwon list it does not show populate city dropdwon
actual problem is State value not set in state variable when i select state
Here is the code:
JsfPage
<p:selectOneMenu id="countrydrop" value="#{user.country}" >
<f:ajax id="countryajex" listener="#{user.statesbycontry()}" render="statedrop"/>
<f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{user.allcontry()}" />
</p:selectOneMenu>
<p:selectOneMenu id="statedrop" value="#{user.ustate}" >
<p:ajax event="change" id="stateajex" listener="#{user.citybystate()}" update="citydrop" />
<f:selectItem itemLabel="Select State" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{user.statelist}"/>
</p:selectOneMenu>
<p:selectOneMenu id="citydrop" value="#{user.city}" >
<f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{user.citylist}" />
</p:selectOneMenu>
jsfManagedBean
String country;
String state;
String city;
List<String> statelist;
List<String> citylist;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public List<String> getStatelist() {
return statelist;
}
public void setStatelist(List<String> statelist) {
this.statelist = statelist;
}
public List<String> getCitylist() {
return citylist;
}
public void setCitylist(List<String> citylist) {
this.citylist = citylist;
}
public List<String> allcontry(){
return od_user_bean.allcountries();
}
public void statesbycontry(){
//Method tested Working well
statelist = od_user_bean.findstatesbycontries(country);
}
public void citybystate(){
System.out.println("State="+state);
if(state != null)
//Method tested Working well
citylist=od_user_bean.findcitybystate(state);
}