I fixed ICE-1505, and along with Mircea, ICE-2485, which partially addresses this issue. Basically, now you can call UIViewRoot.setLocale(Locale) and it sticks. Here's an application code example:
Bean.java
public SelectItem[] getLocales() {
ArrayList items = new ArrayList();
Application application = FacesContext.getCurrentInstance().getApplication();
Iterator supportedLocales = application.getSupportedLocales();
while (supportedLocales.hasNext())
{
Locale locale = (Locale) supportedLocales.next();
items.add(new SelectItem(locale.toString(), locale.getDisplayName()));
}
SelectItem[] locales = new SelectItem[items.size()];
items.toArray(locales);
return locales;
}
public String getSelectedLocale()
{
Locale selectedLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
return selectedLocale.toString();
}
public void setSelectedLocale(String localeString) {
Application application = FacesContext.getCurrentInstance().getApplication();
Iterator supportedLocales = application.getSupportedLocales();
while (supportedLocales.hasNext()) {
Locale locale = (Locale) supportedLocales.next();
if(locale.toString().equals(localeString))
{
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
}
}
page.jspx
<ice:selectOneMenu value="#
{bean.selectedLocale}
" partialSubmit="true">
<f:selectItems value="#
{bean.locales}
"/>
</ice:selectOneMenu>
faces-config.xml
<faces-config >
<application>
<locale-config>
<default-locale>en_US</default-locale>
<supported-locale>fr_CA</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>en_US</supported-locale>
<supported-locale>en_CA</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
</application>
...
</faces-config >
Is it possible that this is again an issue in ICEfaces 1.8 RC1? I've upgraded the libraries for testing purposes in an existing project and I'm experiencing this behaviour now.
I'm setting the locale by FacesContext.getCurrentInstance().getViewRoot().setLocale(locale).