Bonjour,

je me met à JSF et j'ai l'erreur suivante :
javax.servlet.ServletException: helloworld.DictionnaireBean cannot be cast to java.util.Map

J'utilise l'implémentation majorra 2.0.1, mais j'ai eu la même erreur sur d'autre versions.

J'essaye de faire comme sur mon tuto. Sauf qu'il n'est pas marqué pour quelle version de JSF il est fait.

merci de votre aide.

voici mon web.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
 
<?xml version='1.0' encoding='UTF-8'?>
 
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
              version="2.0">
 
    <managed-bean>
        <managed-bean-name>dico</managed-bean-name>
        <managed-bean-class>helloworld.DictionnaireBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <map-entries/>
    </managed-bean>
</faces-config>
mon bean
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
 
public class DictionnaireBean implements Serializable{
    private List<String> listeMots;
 
    public DictionnaireBean() {
        listeMots = new ArrayList<String>();
        listeMots.add("JAVA");
        listeMots.add("J2EE");
        listeMots.add("Spring");
    }
    public int getNombreMots(){
        return listeMots.size();
    }
 
    public String getContenu(){
        StringBuilder stringBuilder = new StringBuilder();
        for (String listeMot : listeMots) {
            stringBuilder.append(listeMot).append("<br/>");
        }
        return stringBuilder.toString();
    }
 
    public void setNouveauMot(String nouveauMot){
        listeMots.add(nouveauMot);
    }
    public String getNouveauMot(){
        return listeMots.get(listeMots.size()-1);
    }
    public List<String> getListeMots() {
        return listeMots;
    }
 
    public void setListeMots(List<String> listeMots) {
        this.listeMots = listeMots;
    }
}
et enfin mon .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
 
<!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<f:view contentType="text/html"/>
<h:head>
    <title>Simple JSF Facelets page</title>
</h:head>
 
<h:body>
    liste de <h:outputText value="#{dico.nombreMots}"/> mots :<br/>
    <h:outputText value="#{dico.contenu}"/><br/>
    <h:form id="dictionnaireForm" >
        <h:inputText id="nouveauMot" value="#{dico.nouveauMot}"/>
        <h:commandButton id="nouveauMotBtn" value="Ajouter" action="dictionnaire"/>
    </h:form>
</h:body>
 
</html>