Bonjour,

J'ai un petit soucis je dois faire un site en JSF avec EJB pour mon ecole.

J'ai fait ma patie EJB ou j'ai mis mes bean

dans le pakage entity j'ai mis la class Utilisateur :

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
package com.id54002.CaveAJP.entity;
 
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
 
/**
 *
 * @author GeantBioHazard
 */
@Entity
public class Utilisateur implements Serializable {
    private static final long serialVersionUID = 1L;
 
    private int idUser;
    private String nom;
    private String prenom;
    private String login;
    private String sexe; 
    private String password;
 
        public Utilisateur() {
    }
 
    public Utilisateur(String nom, String prenom, String login, String sexe, String password) {
        this.nom = nom;
        this.prenom = prenom;
        this.login = login;
        this.sexe = sexe;
        this.password = password; 
    }
 
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public int getIdUser() {
        return idUser;
    }
 
    public void setIdUser(int idUser) {
        this.idUser = idUser;
    }
 
    public String getLogin() {
        return login;
    }
 
    public void setLogin(String login) {
        this.login = login;
    }
 
    public String getNom() {
        return nom;
    }
 
    public void setNom(String nom) {
        this.nom = nom;
    }
 
    public String getPassword() {
        return password;
    }
 
    public void setPassword(String password) {
        this.password = password;
    }
 
    public String getPrenom() {
        return prenom;
    }
 
    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }
 
    public String getSexe() {
        return sexe;
    }
 
    public void setSexe(String sexe) {
        this.sexe = sexe;
    }
 
 
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) idUser;
        return hash;
    }
 
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Utilisateur)) {
            return false;
        }
        Utilisateur other = (Utilisateur) object;
        if (this.idUser != other.idUser) {
            return false;
        }
        return true;
    }
 
    @Override
    public String toString() {
        return "com.id54002.CaveAJP.entity.Utilisateur[id=" + idUser + "]";
    }
 
}
Puis j'ai créer un class dans un pakage daodb : UtilisateurDaoDBLocalBean

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
package com.id54002.CaveAJP.daodb;
 
import com.id54002.CaveAJP.dao.UtilisateurDaoDBLocalLocal;
import com.id54002.CaveAJP.entity.Utilisateur;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
 
/**
 *
 * @author GeantBioHazard
 */
@Stateless
public class UtilisateurDaoDBLocalBean implements UtilisateurDaoDBLocalLocal {
 
    //création de l'entity manager
    @PersistenceContext(unitName="54002-ejbPU")
    EntityManager em;
 
    @Override
    public Utilisateur addUtilisateur(Utilisateur u) {
        em.persist(u);
        return u;
    }
 
    @Override
    public Utilisateur findUtilisateur(int id) {
 
        Utilisateur u = em.find(Utilisateur.class, id);
        return u;
    }
 
    @Override
    public void removeUtilisateur(Utilisateur u) {
        Utilisateur user = em.find(Utilisateur.class, u.getIdUser());
        em.remove(user);
 
    }
 
    @Override
    public void updateUtilisateur(Utilisateur u) {
 
        Utilisateur user = em.find(Utilisateur.class, u.getIdUser());
        em.merge(user);
    }
 
 
}
et son interface UtilisateurDaoDBLocalLocal

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
package com.id54002.CaveAJP.dao;
 
import com.id54002.CaveAJP.entity.Utilisateur;
import javax.ejb.Local;
 
/**
 *
 * @author GeantBioHazard
 */
@Local
public interface UtilisateurDaoDBLocalLocal {
 
    //Utilisateur
    public Utilisateur addUtilisateur(Utilisateur u);
    public Utilisateur findUtilisateur(int id);
    public void updateUtilisateur(Utilisateur u);
    public void removeUtilisateur(Utilisateur u);
 
}
puis dans mon projet war j'ai mis

une page inscription.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
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
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
 
<html>
    <head> 
        <title>Inscription</title>
    </head>
    <body>
        <f:view>
        <h1>Inscription</h1>
        <h:form>
 
         <!-- Le champ texte pour saisir son nom -->
        <h:inputText id="nom" required="true" size="21" maxlength="20"
            value="#{user.nom}">
            <!-- Le label de ce champ texte-->
            <h:outputLabel for="nom" value="Nom : "/>
            <!-- Validateur: le nom doit compter entre 3 et 20 caractères -->
            <f:validateLength minimum="3" maximum="20"/>
        </h:inputText>
        <!-- Affiche les messages du nom -->
        <h:message for="nom" style="color: red"/>
        <br/>
 
     <!-- Le champ texte pour saisir son login -->
        <h:inputText id="login" required="true" size="21" maxlength="20"
            value="#{user.login}">
            <!-- Le label de ce champ texte-->
            <h:outputLabel for="login" value="Login : "/>
            <!-- Validateur: le nom doit compter entre 3 et 20 caractères -->
            <f:validateLength minimum="3" maximum="20"/>
        </h:inputText>
        <!-- Affiche les messages du nom -->
        <h:message for="login" style="color: red"/>
        <br/>
 
        <!-- Le champ texte pour saisir son prénom -->
         <h:inputText id="prenom" required="true" size="21" maxlength="20"
                value="#{user.prenom}">
            <h:outputLabel for="prenom" value="Prénom : "/>
            <f:validateLength minimum="3" maximum="20"/>
         </h:inputText>
            <h:message for="prenom" style="color: red"/>
        <br/>
 
        <!-- Le champ texte pour saisir son mot de passe -->
        <h:inputSecret id="motDePasse" required="true" size="21" maxlength="20"
        value="#{user.password}">
        <h:outputLabel for="motDePasse" value="Password : "/>
        <f:validateLength minimum="3" maximum="20"/>
        </h:inputSecret>
        <h:message for="motDePasse" style="color: red"/>
        <br />
 
        <!-- Radio pour le SEXE -->
 
      <h:selectOneRadio layout="sexe" value="#{user.sexe}">
        <f:selectItem itemValue="Homme" itemLabel="Homme"/>
        <f:selectItem itemValue="Femme" itemLabel="Femme"/>
      </h:selectOneRadio>
        <br />
 
        <h:commandButton value="S'enregistrer" action="success"/>
        </h:form>
       </f:view>
    </body>
</html>
et dans mon faces-config.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
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
<faces-config version="1.2" 
              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_1_2.xsd">
 
<application>
<locale-config>
<default-locale>fr</default-locale>
</locale-config>
</application>
 
<managed-bean>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>com.id54002.CaveAJP.entity.Utilisateur</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>
 
    <navigation-rule>
        <from-view-id>/Inscription.jsp</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/Confirmation.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <from-view-id>/index.jsp</from-view-id>
        <navigation-case>
            <from-outcome>inscription</from-outcome>
            <to-view-id>/Inscription.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>inscriptionMateriel</from-outcome>
            <to-view-id>/InscriptionMateriel.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>personne</from-outcome>
            <to-view-id>/association.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <from-view-id>/InscriptionMateriel.jsp</from-view-id>
        <navigation-case>
            <from-outcome>confirmMateriel</from-outcome>
            <to-view-id>/ConfirmMateriel.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
</faces-config>
donc j'ai bien configurer mon persistence.xml et donc ça me rajoute mes tables dans mysql.

Mais j'aimerais savoir comment et quel procédure je dois effectuer pour que quand je valide mon formulaire ça me rajoute mes données dans la table personne, et aussi supprimer et liste la table.

Je travail sur netbean 6.0.1 avec Glassfish v2

Merci d'avance