Locale[] allCountries = Locale.getAvailableLocales();
Map
for (Locale currentCountry : allCountries)
{
if (! "".equals(currentCountry.getISO3Country()))
{
String countryName =
currentCountry.getDisplayCountry(
FacesContext.getCurrentInstance().getViewRoot(
).getLocale());
uniqueCountries.put(
countryName, currentCountry.getISO3Country());
}
}
Then you can use the map to do whatever. Here is an example to generate a list of JSF SelectItems
List
for (String currentCountryCode : uniqueCountries.keySet())
{
countrySelectItems.add(
new SelectItem(
uniqueCountries.get(currentCountryCode),
currentCountryCode
)
);
}
No comments:
Post a Comment