[] Problème avec JSF 2 et des acti onListener (Windows 7, NetBeans 7.01)

Jacques PIOTROWSKI <[email protected]> Fri, 30 Sep 2011 20:43:59 +0200
Newsgroups gmane.comp.java.netbeans.general.french
Message-ID <[email protected]>
Bonjour,

j'ai dans l'=E9diteur de ma page XHTML, la d=E9sagr=E9able remarque sur =20=

certaines lignes : Unknown property "action".
Tout marche tr=E8s bien : et dans la navigateur et dans le serveur =20
(aucun message bizarre, ou de stack trace bien fournie...)
Sauf si la page commence avec <f:view locale=3D"fr"> au lieu de =20
<f:view>. Dans ce cas, rien ne se passe : la page est bien travaill=E9e =20=

dans les cycles JSF, mais reviens mais dans la langue "fr" ! J'ai =20
pass=E9 un moment avant de trouver...

Le code XHTML/JSF 2 (extrait) :

<?xml version=3D'1.0' encoding=3D'UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd=20
">
<html xmlns=3D"http://www.w3.org/1999/xhtml"
       xmlns:f=3D"http://java.sun.com/jsf/core"
       xmlns:h=3D"http://java.sun.com/jsf/html">


                     <!-- ******************** -->
                     <!-- INTERNATIONALISATION -->
                     <!-- ******************** -->
                     <table>
                         <tr>
                             <td>
                                 <h:commandLink immediate=3D"true" =20
actionListener=3D"#{ChangeLocaleBean.action}">
                                     <f:attribute name=3D"languageCode" =20=

value=3D"en"/>
                                     <h:graphicImage value=3D"images/=20
gb.png" width=3D"64" height=3D"64" style=3D"border-width: 2px"/>
                                 </h:commandLink>
                             </td>
                             <td>
                                 <h:commandLink immediate=3D"true" =20
actionListener=3D"#{ChangeLocaleBean.action}">
                                     <f:attribute name=3D"languageCode" =20=

value=3D"fr"/>
                                     <h:graphicImage value=3D"images/=20
fr.png" width=3D"64" height=3D"64" style=3D"border-width: 2px"/>
                                 </h:commandLink>
                             </td>
                             <td>
                                 <h:commandLink immediate=3D"true" =20
actionListener=3D"#{ChangeLocaleBean.action}">
                                     <f:attribute name=3D"languageCode" =20=

value=3D"it"/>
                                     <h:graphicImage value=3D"images/=20
it.png" width=3D"64" height=3D"64" style=3D"border-width: 2px"/>
                                 </h:commandLink>
                             </td>
                         </tr>
                     </table>

Le code JAVA de la classe ChangeLocaleBean :

import java.io.Serializable;
import java.util.Locale;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

public class ChangeLocaleBean implements Serializable {

     /**
      * Nouvelle Locale.
      */
     private String newLocale;

     /**
      * Demande de changement de Locale.
      * @param event Ev=E8nement GUI (clic sur un drapeau)
      */
     public final void action(final ActionEvent event) {
         final UIComponent component =3D event.getComponent();
         final String languageCode =3D getLanguageCode(component);
         FacesContext.getCurrentInstance().getViewRoot().setLocale(new =20=

Locale(languageCode));
     }

     /**
      * GET code Language Code.
      * @param component Composant GUI
      * @return languageCode
      */
     private  String getLanguageCode(final UIComponent component) {
         final Map<String, Object> attrs =3D component.getAttributes();
         return (String) attrs.get("languageCode");
     }

     /**
      * GET de la Locale courante.
      * @return newLocale
      */
     public final String getNewLocale() {
         this.newLocale =3D =20
FacesContext=20
.getCurrentInstance().getViewRoot().getLocale().getLanguage();
         return newLocale;
     }

     /**
      * SET de la nouvelle Locale.
      * @param pNewLocale Nouvelle Locale
      */
     public final void setNewLocale(final String pNewLocale) {
         this.newLocale =3D pNewLocale;
         FacesContext.getCurrentInstance().getViewRoot().setLocale(new =20=

Locale(this.newLocale));
     }
}

Si quelqu'un a une id=E9e, je suis preneur.
Merci d'avance.

PJ=