I have a backing bean called Test containing a Country object:

public class Test {
        private Country country;
        public Country getCountry()
        public void setCountry(Country cntr)
}

public class Country {
        private int id;
        private String name;
        getters and setters for id and name
}

In my jsp page I want to select the country for Test from a list of countries in a h:selectOneMenu:

<h:selectOneMenu id="country" value="#{test.country}" converter="CountryConverter">
<f:selectItems value="#{countryList}" />
</h:selectOneMenu>


The CountryConverter converts a Country object to the id of that object and vice versa. The countryList is an arraylist of selectItem objects. Each selectItem contains the country object as the value and the name of the country as the label. So the selectOneMenu is hooked to the country property of my test backing bean. The selectOneMenu contains a list of country objects and the converter takes care of the conversion between the Country object and the id of that object.

When I select a country object form the selectOneMenu, the selected country object is passed correctly to the test.country property. Also when converting the test.country back to the string version the new value is returned from the CountryConverter.getAsString method. However, in my jsp page no country is selected: there is no <option value="..." selected>...</option>.

Does anybody know why this is?

I've noticed that when I use the id of the country instead of the country object itself as the value for each selectItem, things do work.

I use myFaces 1.0.9 together with jboss 4.0.

Jan Bols

Reply via email to