Bonjour,
J'ai une application web sous Tomcat, utilisant JSF (rich faces)/facelets pour laquelle je doit avoir de l'internationalisation. une fois authentifié, ça fonctionne avec :
template.xhtml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<f:view locale="localeBean.locale">
...
<h:form id="localeForm" prependId="false">
    <h:commandLink id="FR" actionListener="#{localeBean.changeLocale}" immediate="true">
        <h:graphicImage url="/style/imgs/flag_fr16.png"/>&nbsp;&nbsp;&nbsp;
    </h:commandLink>
    <h:commandLink id="EN" actionListener="#{localeBean.changeLocale}" immediate="true">
        <h:graphicImage url="/style/imgs/flag_uk16.png" />&nbsp;&nbsp;&nbsp;
    </h:commandLink>
</h:form>
...
</f:view>
LocaleBean.java :
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
public class LocaleBean
{
private String locale;
public String getLocale()
    {
    	if (locale== null)
    	{
    		FacesContext context = FacesContext.getCurrentInstance();
    		Locale aLocale = context.getApplication().getDefaultLocale();
    		locale = aLocale.getLanguage();
    	}
    	return locale;
    }
    public void changeLocale(ActionEvent evt)
    {
        System.out.println("changeLocale");
        String componentId = evt.getComponent().getId();
        FacesContext context = FacesContext.getCurrentInstance();
        context.getViewRoot().setLocale(new Locale(componentId));
        locale = componentId;
    }
    public void authenticate()
    {
    ....
    }
...
}
Jusque là tout va bien.


En revanche, je n'arrive pas à faire la même chose sur la page de login : je voudrais pouvoir choisir la langue avant d'avoir à me connecter .
Voici ma page de connexion :
login.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
26
27
28
<h:form id="localeForm" prependId="false">
                  <h:commandLink id="FR" actionListener="#{localeBean.changeLocale}" immediate="true">
                    <h:graphicImage url="/style/imgs/flag_fr16.png" />&nbsp;&nbsp;&nbsp;
                  </h:commandLink>
                  <h:commandLink id="EN" actionListener="#{localeBean.changeLocale}" immediate="true">
                    <h:graphicImage url="/style/imgs/flag_uk16.png" />&nbsp;&nbsp;&nbsp;
                  </h:commandLink>
                </h:form>
 
                <h:form id="loginForm" prependId="false">
                <h1><h:outputText value="#{guiBundle.TITLE_APPLI}" /></h1>
                  <div id="ident">
                    <fieldset id="user-ident">
                      <p>
                        <label><h:outputText value="#{guiBundle.LABEL_USER_LOGIN}" /><span><h:inputText id="j_username" required="true" /></span></label>
                      </p>
                    </fieldset>
                  </div>
                  <div id="password">
                    <fieldset id="user-password">
                      <p>
                        <label><h:outputText value="#{guiBundle.LABEL_USER_PWD}" /><span><h:inputSecret id="j_password" required="true" /></span></label>
                      </p>
                    </fieldset>
                  </div>
                  <h:commandButton type="submit" value="#{guiBundle.BUTTON_APPLY}" 
                         action="#{localeBean.authenticate}"/>
                </h:form>
(1) les images drapeaux ne s'affichent pas (pourtant quand je fait "afficher la source" dans le navigateur, j'ai bien une balise <img src=...)
(2) si je clique à l'endroit où devrait être l'image, je passe dans la trace "changeLocale" mais point de i18n, je reste en langue par défaut.

HEEEEEElp !!