0

I want to select the city depending on the country of origin , but when i submit the city doesn't take à value here is my code jsf

<h:form>
<p:growl id="msgs" showDetail="true" />

<p:panel header="Select a Location" style="margin-bottom:10px;">
    <h:panelGrid columns="2" cellpadding="5">
        <p:outputLabel for="country" value="Country: " />
        <p:selectOneMenu id="country" value="#{maclasse.country}" style="width:150px" >
            <p:ajax listener="#{maclasse.onCountryChange}" update="city" />
            <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
            <f:selectItems value="#{maclasse.countries}" />
        </p:selectOneMenu>

        <p:outputLabel for="city" value="City: " />
        <p:selectOneMenu id="city" value="#{maclasse.city}" style="width:150px">
            <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
            <f:selectItems value="#{maclasse.cities}" />
        </p:selectOneMenu>
    </h:panelGrid>

    <p:separator />
    <p:commandButton value="Submit" update="msgs"  actionListener="#{maclasse.displayLocation}" icon="ui-icon-check" />
</p:panel>

and this ismy bean

public class Maclasse {
private Map<String,Map<String,String>> data ;
private String country; 
private String city;  
private Map<String,String> countries;

// private Map cities; private Map cities=new HashMap();

public void setData(Map<String, Map<String, String>> data) {
    this.data = data;
}

public void setCountries(Map<String, String> countries) {
    this.countries = countries;
}

@PostConstruct
public void init() {
    countries  = new HashMap<String, String>();
    data = new HashMap<String, Map<String,String>>();
    countries.put("USA", "USA");
    countries.put("Germany", "Germany");
    countries.put("Brazil", "Brazil");

    Map<String,String> map = new HashMap<String, String>();
    map.put("New York", "New York");
    map.put("San Francisco", "San Francisco");
    map.put("Denver", "Denver");
    data.put("USA", map);

    map = new HashMap<String, String>();
    map.put("Berlin", "Berlin");
    map.put("Munich", "Munich");
    map.put("Frankfurt", "Frankfurt");
    data.put("Germany", map);

    map = new HashMap<String, String>();
    map.put("Sao Paolo", "Sao Paolo");
    map.put("Rio de Janerio", "Rio de Janerio");
    map.put("Salvador", "Salvador");
    data.put("Brazil", map);
}

public void save(){
    System.out.println("coco je suis la");
    System.out.println("country selected"+getCountry());
    System.out.println("city selected"+getCity());
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
hind
  • 33
  • 2

0 Answers0