i wanted to set the default location of my jsf web project to english, so
i did the following:
faces-config.xml
<application>
<locale-config>
<default-locale>en_EN</default-locale>
<supported-locale>de_DE</supported-locale>
</locale-config>
<resource-bundle>
<base-name>de.hof.tschuwwa.resources.messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
i have a package in my src folder de.hof.tschuwwa.resources
and inside
of that package i have two property files:
messages_de_DE.properties
messages_en_EN.properties
and i tested it in a small xhtml file:
<h:body>
<ui:composition template="/templates/master.xhtml">
<ui:define name="header">
<h:form>
<h:commandButton action="#{navigationService.toLogin}" value="#{msg['login']}" />
<h:commandButton action="#{navigationService.toRegister}" value="#{msg['register']}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
When i start my application it shows the german values and not
the english values. i wanted the default language to be english.
How can i set my default language? The faces-config.xml default-locale
does not seem to work.
Also i need to know how i can change my localization. i wrote this small
service:
@Named
@SessionScoped
public class LanguageService implements Serializable {
private static final long serialVersionUID = 1L;
public void changeLanguage(String language) {
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(language));
}
}
and tried out with the following buttons inside a form:
<p:commandButton id="english" value="English" action="#{languageService.changeLanguage('en')}" immediate="true" />
<p:commandButton id="german" value="Deutsch" action="#{languageService.changeLanguage('de')}" immediate="true" />
but nothing happened when i used them.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…