Bonjour,

Je suis complètement perdu avec j'essai de prendre en main JEE on m'a conseillé de regarder Struts.

Je souhaiterais remplir une liste déroulante avec des données d'une Bdd et je bloque complètement voici ce que j'ai fait.

Ma JSP
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%@include file="Header.jsp" %>
 
<h1>Accueil</h1>
<hr />
 
<div class="centre">
 
<!--GESTION DE LA PARTIE ELEVE-->
<div id="gauche">
	<h2>El&egrave;ve</h2>
	<a href='#'>Voir</a>
	<a href='vueCreerEleve.jsp'>Cr&eacute;er</a>
	<a href='#'>Modifier</a>
</div><!--Fin div eleves-->
quand je clique sur créer je vais vers vueCreerEleve

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
 
<%-- 
    Document   : vueCreerEleve
    Created on : 25 juin 2011, 00:20:12
    Author     : sebastien
--%>
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 
<%@include file="Header.jsp" %>
<h1>Ajouter un Eleve</h1>
<hr><%--Non respect du W3C "</hr>"--%>
<div class="centre">
 
<div class="styleFormulaire">
    <html:form action="formAjoutEleve">
	<p>
 
		<label for="identifiant">Nom:</label>
                <html:text property="nom" value="" size="30" />
                <br>
                 <label for="prenom">Pr&eacute;nom:</label>
                <html:text property="prenom"  value="" size="30" />
 
	</p>
 
	<p>
 
                <label for="sexe">Sexe:</label>
                <html:select property="sexe" >
                <html:option value="H">H</html:option>
                <html:option value="F">F</html:option>
        </html:select>
 
                <br>
 
                <label for="categorie">Cat&eacute;gorie:</label>
 
                <html:select property="categorie" >
                <html:option value="AAC">AAC</html:option>
                <html:option value="B">B</html:option>
                 </html:select>
                <br>
 
          ICI JE VEUX RECUPERER LES MONITEURS QUI SONT DS UNE BDD
                <label for="listeM">Moniteur:</label>
                <html:select property="listeM" >
               <html:optionsCollection property="listeM" value="nom" label="nom"/>
                 </html:select>
                <br>
 
            <label for="age">Age:</label>
                <html:text property="age" value="" size="15" />
 
	</p>
		<input type="submit" value="ok" /> <a href="#">Annuler</a>
</html:form>
</div><!--Fin style formulaire-->
</div><!--Fin div centrage-->
 
 
 
<%@include file="footer.jsp" %>
j'ai une classe FormAjoutEleve

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 
import java.util.LinkedList;
import javax.servlet.http.HttpServletRequest;
import nfe114.projet.entites.Moniteur;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
 
/**
 *
 * @author sebastien
 */
public class formAjoutEleve extends org.apache.struts.action.ActionForm {
 
    private String nom;
    private String prenom;
    private String sexe;
    private String categorie;
    private int age;
    private LinkedList<Moniteur> listeM =new LinkedList<Moniteur>();
 
    private int number;
 
    /**
     * @return
     */
    public String getNom() {
        return nom;
    }
 
    /**
     * @param string
     */
    public void setNom(String string) {
        nom = string;
    }
 
    /**
     * @return
     */
    public int getNumber() {
        return number;
    }
 
    /**
     * @param i
     */
    public void setNumber(int i) {
        number = i;
    }
  /**
     * @return the prenom
     */
    public String getPrenom() {
        return prenom;
    }
 
    /**
     * @param prenom the prenom to set
     */
    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }
 
    /**
     * @return the sexe
     */
    public String getSexe() {
        return sexe;
    }
 
    /**
     * @param sexe the sexe to set
     */
    public void setSexe(String sexe) {
        this.sexe = sexe;
    }
 
      /**
     * @return the age
     */
    public int getAge() {
        return age;
    }
 
    /**
     * @param age the age to set
     */
    public void setAge(int age) {
        this.age = age;
    }
 
    /**
     * @return the listeM
     */
    public LinkedList<Moniteur> getListeM() {
        return listeM;
    }
 
    /**
     * @param listeM the listeM to set
     */
    public void setListeM(LinkedList<Moniteur> listeM) {
        this.listeM = listeM;
    }
 
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getNom() == null || getNom().length() < 1) {
            errors.add("nom", new ActionMessage("error.nom.required"));
            // TODO: add 'error.nom.required' key to your resources
        }
        return errors;
    }
 
    /**
     * @return the categorie
     */
    public String getCategorie() {
        return categorie;
    }
 
    /**
     * @param categorie the categorie to set
     */
    public void setCategorie(String categorie) {
        this.categorie = categorie;
    }
 
    /**
     *
     */
    public formAjoutEleve() {
        super();
        // TODO Auto-generated constructor stub
    }
 
 
 
}
une classe ActionAjoutEleve
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
 
public class ActionAjoutEleve extends org.apache.struts.action.Action {
 
    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
 
 
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception 
    {
         System.out.println("je suis dans ActionAjoutEleve");
         DaoMoniteur dao = DaoFactory.createDAOMoniteur();
         List<Moniteur> liste = dao.selectNom();
 
         formAjoutEleve formEleve=new formAjoutEleve();
         formEleve.setListeM((LinkedList<Moniteur>) liste);
 
        return mapping.findForward(SUCCESS);
    }
}
ça ne fonctionne pas.
Est ce qu'il faut que je créer une classe action avec tous les DAO etc.. que j'appellerais lorsque je clique sur "créer eleves" qui initialiserais la liste déroulante?? il me faut créer encore une classe Action avec tous les DAO pour récupérer les données du formulaire et enregistrer l'élève ça fait beaucoup de classe juste pour une liste déroulante.
c'est embrouillé dans ma tête si quelqu'un peut m'aider ce serait vraiment sympa.

je regardé ce post http://www.developpez.net/forums/d10...lante-numeros/

ha oui mon fichier struts-config.xml

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 <action-mappings>
        <action  input='/formAjoutEleve' name="formAjoutEleve" path="/formAjoutEleve" scope="request" type="projet.actions.ActionAjoutEleve"/>