Voici mon code qui fonctionne :
dans faces-config.xml:
1 2 3 4 5 6 7 8 9
| <application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<message-bundle>be.dzafer.bundle.MessageResource</message-bundle>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>fr_BE</supported-locale>
<supported-locale>nl_BE</supported-locale>
</locale-config>
</application> |
dans les pages jsf:
<f:loadBundle basename="be.dzafer.bundle.MessageResource" var="msg" />
dans le code du bean ou autre
1 2 3 4 5
| public void onChooseLocale(ActionEvent event) {
String current = event.getComponent().getId();
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale(locales.get(current));
} |
dans la page jsf choix de la langue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <h:form>
<h:commandLink id="f" action="chooseLocale"
actionListener="#{loginCtrl.onChooseLocale}">
<h:outputText value="FR" />
</h:commandLink>
<h:outputText value=" "/>
<h:commandLink id="e" action="chooseLocale"
actionListener="#{loginCtrl.onChooseLocale}">
<h:outputText value="EN" />
</h:commandLink>
<h:outputText value=" "/>
<h:commandLink id="n" action="chooseLocale"
actionListener="#{loginCtrl.onChooseLocale}">
<h:outputText value="NL" />
</h:commandLink>
</h:form> |
Partager