bonjour,
j'ai crée une méthode qui sauvegarde les données dans la base de donnée et ça fonctionne correctement.maintenant j'ai mis en place un formulaire en jsf et j'aimerais bien sauvegarder les champs dans ma base de donnée.Ja'i essayé d'appeler ma methode de sauvegarde dans la page jsf( qui marche très bien) mais elle ne marche pas.
voci mon code jsf
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 <?xml version='1.0' encoding='UTF-8' ?> <!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" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"> <h:head> <title> new data </title> </h:head> <h:body> <ui:include src="header.xhtml" /> <p:panel header="General"> <h:panelGrid columns="2"> <h:outputText value="Societé " /> <p:selectOneMenu value="#{nouvelleCompagne.societe}"> <f:selectItem itemLabel="choisissez votre societé" itemValue="" /> <f:selectItem itemLabel="Somatel" itemValue="somatel" /> <f:selectItem itemLabel="Syscomedia" itemValue="syscomedia" /> <f:selectItem itemLabel="Option 3" itemValue="option3" /> </p:selectOneMenu> <h:outputText value="Nom Compagne " /> <p:inputText id="NomCompagne" value="#{nouvelleCompagne.compagne}"/> <h:outputText value="Description " /> <p:inputTextarea rows="4" cols="60" value="#{nouvelleCompagne.description}"/> </h:panelGrid> </p:panel> <p:panel header="Budget et Invistissement"> <h:panelGrid columns="2"> <h:outputText value="Type compagne" /> <p:selectOneRadio id="options" value="#{nouvelleCompagne.type_compagne}" > <f:selectItem itemLabel="A" itemValue="A" /> <f:selectItem itemLabel="B" itemValue="B" /> </p:selectOneRadio> <h:outputText value="Prix Unitaire" /> <p:inputText id="PrixUnitaire" required="true" value="#{nouvelleCompagne.prix_unitaire}"/> <h:outputText value="Type d'investissement" /> <p:selectOneRadio id="options1" value="#{nouvelleCompagne.type_invest}"> <f:selectItem itemLabel="Budget" itemValue="budget" /> <f:selectItem itemLabel="Nombre" itemValue="nb" /> </p:selectOneRadio> <h:outputText value="Critère d'envoi" /> <p:selectManyCheckbox value="#{nouvelleCompagne.critere_envoi}"> <f:selectItem itemLabel="Sex" itemValue="sex" /> <f:selectItem itemLabel="Age" itemValue="age" /> <f:selectItem itemLabel="Ville" itemValue="ville" /> <f:selectItem itemLabel="Revenu" itemValue="revenu" /> </p:selectManyCheckbox> <p:separator /> <p:separator /> <!-- style="width:500px;height:20px;color:red;" --> </h:panelGrid> </p:panel> <p:panel header="Cible et Critere"> <h:panelGrid columns="2"> <h:outputText value="Public visé " /> <p:selectOneRadio id="options3" value="#{nouvelleCompagne.public_vise}"> <f:selectItem itemLabel="ALL" itemValue="all" /> <f:selectItem itemLabel="Male" itemValue="male" /> <f:selectItem itemLabel="Femèle" itemValue="femele" /> </p:selectOneRadio> <h:outputText value="Tranche d'âge " /> <p:selectOneRadio id="options4" value="#{nouvelleCompagne.tranche_age}"> <f:selectItem itemLabel="ALL" itemValue="all" /> <f:selectItem itemLabel="Interval Age" itemValue="Interval Age" /> </p:selectOneRadio> <h:outputText value="Revenue " /> <p:selectManyCheckbox value="#{nouvelleCompagne.consommation}"> <f:selectItem itemLabel="High" itemValue="high gros client" /> <f:selectItem itemLabel="Upper medium" itemValue="upper medium" /> <f:selectItem itemLabel="Medium" itemValue="medium" /> <f:selectItem itemLabel="Lower Medium" itemValue="lower medium" /> <f:selectItem itemLabel="Low" itemValue="low" /> <f:selectItem itemLabel="Under" itemValue="under" /> </p:selectManyCheckbox> <h:outputText value="Critère ville " /> <p:selectOneRadio id="options5" value="#{nouvelleCompagne.critere_ville}"> <f:selectItem itemLabel="ville specifique" itemValue="ville specifique" /> <f:selectItem itemLabel="delegation specifique" itemValue="delegation specifique" /> </p:selectOneRadio> <p:outputLabel value="Total Client sélectionnés " /> <p:outputLabel value="0" style="color:blue"/> <p:outputLabel value="Budget estimé " /> <p:outputLabel value="0" style="color:blue" /> </h:panelGrid> </p:panel> <p:commandButton value="OK" action="test2.xhtml" /> <p:commandButton value="save" action="#{nouvelleCompagne.addCompagne(name, description, texte, header, budget, nb)}" /> </h:body> </html>
et voici mon bean
and i have no errors
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 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.bean; import java.io.Serializable; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.List; import java.util.logging.*; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; //import javax.persistence.Entity; /** * * @author Haythem */ @ManagedBean @SessionScoped public class NouvelleCompagne implements Serializable{ static Logger log = Logger.getLogger(NouvelleCompagne.class.getName()); // paramètres générals private String societe; private String compagne; private String description; // paramètres budget & investissement private String type_compagne; private double prix_unitaire; private String type_invest; private String texte; private String header; private List<String> critere_envoi; // cibles et critères private String public_vise; private String tranche_age; private List<String> consommation; private String critere_ville; //somme total private double budget_estime; private int nbre_clients; /*--------------------------------------------------------------- * DIVERS METHODES *--------------------------------------------------------------- */ public double calculeSomme(double prix_unitaire, int nb){ budget_estime= prix_unitaire* nb; return budget_estime; } public static Boolean AddCompagne(String name, String description, String texte, String header, Double budget, int nb) { Statement stmt = null; Boolean res=false; Connection conn=null; String sqlInsert= "insert into compagne (name , description, texte, header, budget, nb ) values ('"+ name + "' , '"+ description + "', '"+ texte + "', '"+ header + "', '"+ budget + "', '"+ nb+ "')"; try { System.out.println("1"); conn=com.util.ConnectionPool.getConnection(); System.out.println("2"); stmt = conn.createStatement(); System.out.println("3"); stmt.execute(sqlInsert); System.out.println("success"); conn.commit(); res = true; } catch (SQLException e) { try { System.out.println("erreur"); conn.rollback(); } catch (SQLException e1) { //log.error(e1.getMessage()); System.out.println("erreur2"); e1.printStackTrace(); } //log.error(e.getMessage()); e.printStackTrace(); } finally { try { stmt.close(); } catch (SQLException e) { //log.error(e.getMessage()); e.printStackTrace(); } } //log.debug("New Client Inserted:"+res+"\n"); return res; } /*------------------------------------------------------------------------------------------------ ----------------------------------- GETTER AND SETTER -------------------------------------------- * ----------------------------------------------------------------------------------------------- */ public double getBudget_estime() { return budget_estime; } public void setBudget_estime(double budget_estime) { this.budget_estime = budget_estime; } public String getCompagne() { return compagne; } public void setCompagne(String compagne) { this.compagne = compagne; } public List<String> getCritere_envoi() { return critere_envoi; } public List<String> getConsommation() { return consommation; } public void setConsommation(List<String> consommation) { this.consommation = consommation; } public void setCritere_envoi(List<String> critere_envoi) { this.critere_envoi = critere_envoi; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getNbre_clients() { return nbre_clients; } public void setNbre_clients(int nbre_clients) { this.nbre_clients = nbre_clients; } public double getPrix_unitaire() { return prix_unitaire; } public void setPrix_unitaire(double prix_unitaire) { this.prix_unitaire = prix_unitaire; } public String getPublic_vise() { return public_vise; } public void setPublic_vise(String public_vise) { this.public_vise = public_vise; } public String getSociete() { return societe; } public void setSociete(String societe) { this.societe = societe; } public String getTranche_age() { return tranche_age; } public void setTranche_age(String tranche_age) { this.tranche_age = tranche_age; } public String getType_compagne() { return type_compagne; } public void setType_compagne(String type_compagne) { this.type_compagne = type_compagne; } public String getType_invest() { return type_invest; } public void setType_invest(String type_invest) { this.type_invest = type_invest; } public String getCritere_ville() { return critere_ville; } public void setCritere_ville(String critere_ville) { this.critere_ville = critere_ville; } public String getHeader() { return header; } public void setHeader(String header) { this.header = header; } public String getTexte() { return texte; } public void setTexte(String texte) { this.texte = texte; } }
Partager