Bonjour, je suis en train de coder un formulare avec nom, prenom, biographie et la position en struts 2 et nom, prenom, biographie sont des textfield, mais position est un champ select où je dois selectionner la position parmi celles contenues dans une methode de la facade qui est de type Collection<String>, mais je n'arrive pas à ajouter cette Collection à l'attribut list de la balise tag select et il m'affiche toujours l'erreur:
tag 'select', field 'list', name 'positions': The requested list key 'positions' could not be resolved as a collection/array/map/enumeration/iterator type
Voici la classe ActionAffichage:
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
public class ActionAffichage extends ActionSupport implements ApplicationAware {
    private FacadeJoueur facade;
    private String position;
    private Collection<String> positions;
    private String nom;
    private String prenom;
    private String biographie;
    private int id;
 
    public int getId() {
        return id;
    }
 
    public void setId(int id) {
        this.id = id;
    }
 
    public Collection<String> getPositions() {
        return facade.getAllPositions();
    }
 
    public String getPosition() {
        return position;
    }
 
    public void setPosition(String position) {
        this.position = position;
    }
 
    public String getNom() {
        return nom;
    }
 
    public void setNom(String nom) {
        this.nom = nom;
    }
 
    public String getPrenom() {
        return prenom;
    }
 
    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }
 
    public String getBiographie() {
        return biographie;
    }
 
    public void setBiographie(String biographie) {
        this.biographie = biographie;
    }
    @Override
    public String execute() throws Exception{
        try {
 
            for (String s : getPositions()) {
                position = s;
                this.setPosition(position);
 
                switch (position) {
                    case "AILIER":
                        id=facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("AILIER"));
                        break;
                    case "MENEUR":
                        facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("MENEUR"));
                        break;
                    case "PIVOT":
                        facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("PIVOT"));
                        break;
                    case "ARRIERE":
                        facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("ARRIERE"));
                        break;
                    case "AILIER FORT":
                        facade.ajouterJoueur(nom, prenom, biographie, Joueur.Position.valueOf("AILIER FORT"));
                        break;
                }
            }
            return SUCCESS;
        } catch (JoueurDejaExistant joueurDejaExistant) {
            this.addFieldError("nom", getText("erreur.joueur"));
        } catch (PositionNotFoundException e) {
            this.addFieldError("position",getText("erreur.position"));
        }
       return INPUT;
    }
 
    @Override
    public void validate() {
        if (Objects.isNull(nom) || nom.length()<4){
            this.addFieldError("nom",getText("erreur.nom"));
        }
        if (Objects.isNull(prenom) || prenom.length()<4){
            this.addFieldError("prenom",getText("erreur.prenom"));
        }
        if (Objects.isNull(biographie) || biographie.length()<4){
            this.addFieldError("biographie",getText("erreur.biographie"));
        }
        if (Objects.isNull(position)){
            this.addFieldError("position",getText("erreur.champposition"));
        }
    }
    @Override
    public void setApplication(Map<String, Object> map) {
        this.facade=(FacadeJoueur) map.get("facade");
        if(Objects.isNull(this.facade)){
            this.facade=new FacadeJoueurImpl();
            map.put("facade",this.facade);
        }
    }
}
Voici le page accueil.jsp:
Code jsp : 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
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title><s:text name="jouer"/></title>
</head>
<body>
    <h1> <s:text name="jouer"/> </h1>
 
    <s:form action="details">
        <s:textfield name="nom" key="nomjoueur"/>
        <s:textfield name="prenom" key="prenomjoueur"/>
        <s:select name="positions" list="%{#session.listePositions}" />
        <s:textarea key="biographie"/>
        <s:submit />
    </s:form>
 
</body>
</html>
Je vous remercie d'avance pour votre aide.