I got
j_idt7:city: Validation Error: Value is not valid
Cutting to the cheese, ManagedBean code:
//few imports here
@ManagedBean
@SessionScoped
public class CountriesAndCities implements Serializable{
private List<SelectItem> countries;
private List<SelectItem> cities;
private Map<String,List> m;
private String selectedCountry;
public String getSelectedCountry() {
return selectedCountry;
}
public void setSelectedCountry(String selectedCountry) {
this.selectedCountry = selectedCountry;
}
public CountriesAndCities(){
countries = new ArrayList<SelectItem>();
cities = new ArrayList<SelectItem>();
m = new HashMap<String,List>();
m.put("France", Arrays.asList("paris","marseille"));
m.put("England", Arrays.asList("Munchester","liverpoor"));
}
public List<SelectItem> getCountries(){
cities.removeAll(cities);
countries.removeAll(countries);
countries.add(new SelectItem("select country"));
for(Map.Entry<String, List> entry: m.entrySet()){
countries.add(new SelectItem(entry.getKey()));
}
return countries;
}
public List<SelectItem> getCities(){
for(Map.Entry<String, List> entry: m.entrySet())
{if(entry.getKey().toString().equals(selectedCountry)){
cities.addAll(entry.getValue());
break;
}
}
return cities;
}
public void checkSelectedCountry(ValueChangeEvent event){
selectedCountry = event.getNewValue().toString();
}
Here's the snippet of my .xhtml :
<h:selectOneMenu immediate="true" value="#{countriesAndCities.selectedCountry}"
onchange="submit()" valueChangeListener="#{countriesAndCities.checkSelectedCountry}">
<f:selectItems value="#{countriesAndCities.countries}"></f:selectItems>
</h:selectOneMenu>
<br/>
<h:selectOneMenu id="city">
<f:selectItems value="#{countriesAndCities.cities}"></f:selectItems>
</h:selectOneMenu>
</h:form>
The code does what is supposed to be, But I get the error mentioned above at first line, only when i click on England and select country choices, I dunno why, I've written the same task in Ajaxized code, and It worked fine, any hand would be dead thankful .