Hi @all,
I´m struggling around with the converters and maybe someone can give me,
what I´m doing wrong.
I use the following code in my web-page:
<tr:selectOneChoice id="country"
value="#{signUpForm.country}"
simple="true"
required="true"
converter="#{commonDataHelper.countryConverter}"
unselectedLabel="#{messages['label.address.country.unselected']}">
<f:selectItems value="#{commonDataHelper.countrySelectionList}" />
</tr:selectOneChoice>
The selectItems are filled by the following method:
public Map<String, Country> getCountrySelectionList() {
Map<String, Country> sortedCountryList = new TreeMap<String,
Country>();
for (Country country : getCountryManager().getAllCountries()) {
String label = CountryConverter.getMessage(country);
sortedCountryList.put(label, country);
}
return sortedCountryList;
}
Now as soon as my converter´s getAsObject()-method is called, I get the
toString() representation of my country´s object as the String-parameter.
But this is not what I need, as this is of no value to me. What would be
more interesting would be the selected label, from which I can convert back
to my entity. If I return a Map<String, String> the label is given
correctly, but then - after returning the correct Country-Object - it
obviously cannot find this object in it´s selectionList and returns an
error.
Is there anything I have to keep in mind or do I absolutely misunderstand
the converters? For my understanding the getAsString()-method should
convert an object into a String, which is used in the select-box and the
getAsObject()-methods reconverts this String back to an object. I don´t
think it´s meant to be, that the conversion is relying on the
representation of the toString()-method and that this should be used for
comparison. This would be a very unreliable option.
Maybe someone can help me to understand this whole thing.
Thanks
Thomas