The LocaleConverter (pe:convertLocale) converts a locale string (for example 'de_DE') to a java.util.Locale object and reverse.
Enter a new locale here (A valid locale for example is de_DE):
Available locales:
Source
<p:messages id="messages"/>
Enter a new locale here (A valid locale for example is de_DE):<br/>
<p:inputText id="enteredLocale" value="#{localeController.enteredLocale}" required="true">
<pe:convertLocale/>
</p:inputText>
<h:panelGroup layout="block" style="margin-top: 10px;margin-bottom: 10px;">
<p:commandButton value="Add" action="#{localeController.add}" update="messages addedLocales enteredLocale"/>
</h:panelGroup>
Available locales:<br/>
<h:selectManyListbox id="addedLocales" value="#{localeController.selectedLocales}" style="width: 200px;">
<pe:convertLocale/>
<f:selectItems value="#{localeController.addedLocales}"/>
</h:selectManyListbox>
@Named
@ViewScoped
public class LocaleController implements Serializable {
private static final long serialVersionUID = 1L;
private List<Locale> selectedLocales;
private Locale enteredLocale;
private List<Locale> addedLocales;
public LocaleController() {
addedLocales = new ArrayList<>();
addedLocales.add(Locale.GERMANY);
addedLocales.add(Locale.ITALIAN);
addedLocales.add(Locale.KOREA);
}
public void add() {
addedLocales.add(enteredLocale);
}
public Locale getEnteredLocale() {
return enteredLocale;
}
public void setEnteredLocale(final Locale enteredLocale) {
this.enteredLocale = enteredLocale;
}
public List<Locale> getAddedLocales() {
return addedLocales;
}
public void setAddedLocales(final List<Locale> addedLocales) {
this.addedLocales = addedLocales;
}
public List<Locale> getSelectedLocales() {
return selectedLocales;
}
public void setSelectedLocales(final List<Locale> selectedLocales) {
this.selectedLocales = selectedLocales;
}
}