Bjrrr

j'ai crée ces 2 fichier et je sé pa comment je fait l'ajout

UtilisateurFacade.java

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
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package Session;
 
import Table.Utilisateur;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
 
/**
 *
 * @author admin
 */
@Stateless
public class UtilisateurFacade implements UtilisateurFacadeLocal, UtilisateurFacadeRemote {
    @PersistenceContext
    private EntityManager em;
 
    public void create(Utilisateur utilisateur) {
        em.persist(utilisateur);
    }
 
    public void edit(Utilisateur utilisateur) {
        em.merge(utilisateur);
    }
 
    public void remove(Utilisateur utilisateur) {
        em.remove(em.merge(utilisateur));
    }
 
    public Utilisateur find(Object id) {
        return em.find(Utilisateur.class, id);
    }
 
    public List<Utilisateur> findAll() {
        return em.createQuery("select object(o) from Utilisateur as o").getResultList();
    }
 
}
Utilisateur.java


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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package Table;
 
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
 
/**
 *
 * @author admin
 */
@Entity
public class Utilisateur implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
 
    private Long id;
   @Column(name="CIN")
    private Long CIN;
 
    public Long getCIN() {
        return CIN;
    }
 
    public void setCIN(Long CIN) {
        this.CIN = CIN;
    }
 
    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 getType() {
        return Type;
    }
 
    public void setType(String Type) {
        this.Type = Type;
    }
    @Column(name="Nom")
   private String Nom;
     @Column(name="Prenom")
    private String Prenom;
     @Column(name="Login")
    private String Login;
     @Column(name="Password")
    private String Password;
 
    public String getLogin() {
        return Login;
    }
 
    public void setLogin(String Login) {
        this.Login = Login;
    }
 
    public String getPassword() {
        return Password;
    }
 
    public void setPassword(String Password) {
        this.Password = Password;
    }
 @Column(name="Type")
     private String Type;//soit admin , soit utilisateur normal
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        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.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
 
    @Override
    public String toString() {
        return "Table.Utilisateur[id=" + id + "]";
    }
 
}

add_user.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package project;
 
import Session.UtilisateurFacadeRemote;
import Table.Utilisateur;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.PasswordField;
import com.sun.webui.jsf.component.RadioButton;
import com.sun.webui.jsf.component.TextField;
import javax.ejb.EJB;
import javax.faces.FacesException;
import javax.faces.event.ValueChangeEvent;
 
/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version add_user.java
 * @version Created on 3 avr. 2011, 14:28:56
 * @author Maryem
 */
 
public class add_user extends AbstractPageBean {
    @EJB
    UtilisateurFacadeRemote ufr;
    Utilisateur uti= new Utilisateur();
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
 
    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    private TextField cin = new TextField();
 
    public TextField getCin() {
        return cin;
    }
 
    public void setCin(TextField tf) {
        this.cin = tf;
    }
    private TextField nom = new TextField();
 
    public TextField getNom() {
        return nom;
    }
 
    public void setNom(TextField tf) {
        this.nom = tf;
    }
    private TextField prenom = new TextField();
 
    public TextField getPrenom() {
        return prenom;
    }
 
    public void setPrenom(TextField tf) {
        this.prenom = tf;
    }
    private TextField login = new TextField();
 
    public TextField getLogin() {
        return login;
    }
 
    public void setLogin(TextField tf) {
        this.login = tf;
    }
    private PasswordField password1 = new PasswordField();
 
    public PasswordField getPassword1() {
        return password1;
    }
 
    public void setPassword1(PasswordField pf) {
        this.password1 = pf;
    }
    private PasswordField password2 = new PasswordField();
 
    public PasswordField getPassword2() {
        return password2;
    }
 
    public void setPassword2(PasswordField pf) {
        this.password2 = pf;
    }
    private RadioButton admin = new RadioButton();
 
    public RadioButton getAdmin() {
        return admin;
    }
 
    public void setAdmin(RadioButton rb) {
        this.admin = rb;
    }
    private RadioButton user = new RadioButton();
 
    public RadioButton getUser() {
        return user;
    }
 
    public void setUser(RadioButton rb) {
        this.user = rb;
    }
 
    // </editor-fold>
 
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public add_user() {
    }
 
    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        prenom.setText("");
        nom.setText("");
        cin.setText("");
        password1.setText("");
        password2.setText("");
        login.setText("");
 
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
 
 
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("add_user Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
 
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
    }
 
    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }
 
    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    }
 
    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }
 
    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }
 
    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }
 
    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }
 
    public void password1_processValueChange(ValueChangeEvent event) {
    }
 
    public String button1_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        Long c=new Long (cin.getText().toString());
        uti.setCIN(c);
        uti.setNom(nom.getText().toString());
        uti.setPrenom(prenom.getText().toString());
        uti.setPassword(password1.getText().toString());
        if (admin.isChecked()== true ){
            uti.setType("Admin");
        }
        if (user.isChecked()== true ){
            uti.setType("User");
        }
        ufr.create(uti);
 
        return null;
    }
 
    public String ajout_user_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
 
        return null;
    }
 
    public String supp_user_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        return "case1";
    }
 
    public String chang_user_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        return "case2";
    }
 
    public String button2_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        return null;
    }
 
    public String imageHyperlink1_action() {
        // TODO: Process the action. Return value is a navigation
        // case name where null will return to the same page.
        return "case3";
    }
 
}
persistence.xml

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="EJBpfePU" transaction-type="JTA">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <jta-data-source>pfe</jta-data-source>
    <properties>
      <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>