Bonjour,

Tout est dans le titre. Je veux faire un truc de ce genre :

Classe contenant ma variable statique :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
public class MesConstantes {
      public static final String MA_VARIABLE = "qq chose";
}
Accès à ma variable dans la page test.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
<?xml version="1.0" encoding="UTF-8" ?>

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">
       ...
       <h:outputText value="#{MesConstantes.MA_VARIABLE}" />
       ...
</ui:composition>
Certains proposent de passer par des getters dans le bean et d'y retourner la variable statique mais y a-t-il que ça comme solution ?

Solution avec getter :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
@ManagedBean(name="monBean")
public class ManagedBean {
 
      ...
      public String getVar() {
             return MesConstantes.MA_VARIABLE;
      }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8" ?>

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">
       ...
       <h:outputText value="#{monBean.var}" />
       ...
</ui:composition>
Merci d'avance