I implemented internationalization in my JSF application as described here .
But I ran into a problem: when I change the language, all the texts on my page change. But then, if I click on the navigation link to go to another page, the language standard will return to the standard language!
I think I missed something. So I provide my code below and hope you can help:
LocaleBean.java:
@ManagedBean(name="locale")
@SessionScoped
public class LocaleBean {
private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
public Locale getLocale() {
return locale;
}
public void setLanguage(String language) {
locale = new Locale(language);
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
public String getLanguage() {
return locale.getLanguage();
}
}
JSF part (part of my template):
<h:outputText value=" #{text['common.language']}: " />
<h:selectOneMenu value="#{locale.language}" onchange="submit()">
<f:selectItem itemValue="de" itemLabel="Deutsch" />
<f:selectItem itemValue="en" itemLabel="English" />
</h:selectOneMenu>
faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<locale-config>
<default-locale>de</default-locale>
<supported-locale>en</supported-locale>
</locale-config>
<resource-bundle>
<base-name>org.dhbw.stg.wwi2008c.mopro.ui.text</base-name>
<var>text</var>
</resource-bundle>
</application>
</faces-config>
I then Text.java from the tutorial and just changed the package path.
Here is my directory:

If something important is missing, ask for it, please.
source
share