Bonjour ,
j'ai un problème avec l'internationalisation de jsf , je perd la langue courante si j’accède à mes pages directement avec l'url (exemple /monApplication/monPage.jsf)
si j'utilise la navigation de jsf tout fonctionne correctement .
voici mon code
Langue.java :
langue.xhtml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.Locale; import javax.faces.context.FacesContext; /** * @author wissem * */ public class Langue { public Langue() { } public String activerFR() { FacesContext context = FacesContext.getCurrentInstance(); context.getViewRoot().setLocale(Locale.FRENCH); return null; } public String activerEN() { FacesContext context = FacesContext.getCurrentInstance(); context.getViewRoot().setLocale(Locale.ENGLISH); return null; } }
faces-config.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"> <head> <title>My Facelets Page</title> <meta http-equiv="keywords" content="enter,your,keywords,here" /> <meta http-equiv="description" content="A short description of this page." /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> </head> <body> <f:view> <h:form> <table > <tr> <td> <h:commandLink action="#{langue.activerFR}" immediate="true"> <h:outputText value="#{msg.langue_fr}" ></h:outputText> </h:commandLink> </td> <td> <h:commandLink action="#{langue.activerEN}" immediate="true"> <h:outputText value="#{msg.langue_en}" ></h:outputText> </h:commandLink> </td> </tr> </table> </h:form> </f:view> </body> </html>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 <managed-bean> <managed-bean-name>langue</managed-bean-name> <managed-bean-class>tn.app.name.web.langue.Langue</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> <locale-config> <default-locale>en</default-locale> <supported-locale>fr</supported-locale> </locale-config> <resource-bundle> <base-name>tn.app.name.web.langue.MessageBundle</base-name> <var>msg</var> </resource-bundle>
Partager