Bonjour à tous,
Je rencontre un problème avec un objet Primefaces.
Le DataTable - Row Editing (http://www.primefaces.org/showcase/u...RowEditing.jsf) permet l'édition des cellules en direct sur la page.
Mon problème est le suivant :
J'ai un tableau avec pour chaque ligne des véhicules différents (Immatriculation, Date, prix....). Je cherche à pouvoir faire en sorte de supprimer un véhicule depuis ce tableau grâce au RowEditing, j'y arrive, mais une fois ce dernier supprimé de ma BD, je n'arrive pas à instantanément le faire disparaître du DataTable, sûrement un problème de rafraîchissement mais lequel ?
Mon DataTable RowEditing :
Et ma fonction qui supprime :
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 pou:dataTable id="listVehiculeTable" value="#{GestionClient.listVehicule}" var="listeVehicule" styleClass="dataTable" editable="true" paginator="true" resizableColumns="true" rows="10" rowsPerPageTemplate="5,10,15" sortMode="multiple"> <pou:ajax event="rowEdit" listener="#{GestionClient.editVehicule}" update=":form:messages, listVehiculeTable"/> <pou:ajax event="rowEditCancel" listener="#{GestionClient.removeVehicule}" update=":form:messages, listVehiculeTable"/> <pou:column headerText="Immat." filterBy="immatriculation"> <h:outputText value="#{listeVehicule.immatriculation}"/> </pou:column> <pou:column headerText="Marque" filterBy="marque"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.marque}"/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.marque}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="Modele" filterBy="modele"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.modele}"/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.modele}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="Version" filterBy="version"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.version}"/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.version}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="KM"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.kilometrage}"/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.kilometrage}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="CV" filterBy="puissance"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.puissance} cv"/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.puissance}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="Energie" filterBy="energie"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.energie}"/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.energie}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="PV Depot"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.pv_depot} "/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.pv_depot}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="MEC"> <pou:cellEditor> <f:facet name="output"> <h:outputText value="#{listeVehicule.date_mec_bonne}"/> </f:facet> <f:facet name="input"> <pou:inputText value="#{listeVehicule.date_mec_bonne}" style="width: 100%;"/> </f:facet> </pou:cellEditor> </pou:column> <pou:column headerText="Edition"> <pou:rowEditor /> </pou:column> <f:facet name="footer"> Total : #{GestionClient.nbVehicule} véhicules enregistrés. </f:facet> </pou:dataTable>
D'avance merci de votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public void removeVehicule(RowEditEvent event) throws IOException { FacesMessage msg = new FacesMessage("Véhicule supprimé", ((Voiture) event.getObject()).getImmatriculation()); //Requete sql de suppression du véhicule String sql = "DELETE FROM `voiture` WHERE `immatriculation` = '" + ((Voiture) event.getObject()).getImmatriculation() + "'"; System.out.println("Requete sql suppresion vehicule : " + sql); try { Statement state = this.bdd.createStatement(); state.executeUpdate(sql); } catch (SQLException e) { System.out.println("Erreur suppression vehicule: " + e.getMessage()); } FacesContext.getCurrentInstance().addMessage(null, msg); }
Partager