0

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);
}
NIkunj Patel
  • 33
  • 1
  • 1
  • 8
  • Works great here: https://www.primefaces.org/showcase/ui/ajax/dropdown.xhtml. And for code that is not working, Stackoverflow sort of **requires** a [mcve], see [ask] and you can edit questions by pressing the edit button below it. Code is comments is unreadble AND should contain comments. And 'not working' is not 'smart' (specific, measurable etc...). And it is PrimeFaces related, so add that as a tag – Kukeltje Dec 28 '17 at 19:33
  • Create a new fully empty jsf project. Copy just the parts that you posted above in there, does it run? Most likely not so it is not complete. You have 3 selects, can't you reproduce with 2? Most likely not, so it is not 'minimal'. Please make it into a [mcve] and find the differences with the PF showcase – Kukeltje Dec 28 '17 at 23:46
  • Then read all this https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value/2120183#2120183 – Kukeltje Dec 29 '17 at 07:33
  • Have you confirmed that your `User.citybystate()` listener is called after change event on `statedrop` dropdown ?? – Kishor Prakash Dec 29 '17 at 09:50

0 Answers0