bonjour tout le monde je voudrais afficher le détail d'un client a partir d'une liste des clients auxquels je passe l'id_client a travers le lien edit,mais les champs sont vides.
voila le code:
listerclient.jsp:
editClient.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 <body> <f:view> <h:form> <h:dataTable id="clients" value="#{clientListBean.affichage}" var="clients" border="1"> <h:column> <f:facet name="header"> <h:outputText value="Nom"/> </f:facet> <h:outputText value="#{clients.nom}" /> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Prenom"/> </f:facet> <h:outputText value="#{clients.prenom}" /> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Edit"/> </f:facet> <h:commandLink id="Edit" action="editClient" actionListener="#{clientBean.clientDetail}" > <h:outputText value="Edit" /> <f:param id="editId" name="id" value="#{clients.id_client}" /> </h:commandLink> </h:column> </h:dataTable> </h:form> </f:view> </body>
Client.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 <body> <f:view> <h:form > <table> <tr> <td><h:outputText value="Nom:" /> </td> <td><h:inputText value="#{clientBean.nom}"/></td> </tr> <tr> <td><h:outputText value="Prenom:" /></td> <td> <h:inputText value="#{clientBean.prenom}"> </h:inputText></td> </tr> </table> </h:form> </f:view> </body>
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 package com.connexion; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import javax.faces.component.UIParameter; import javax.faces.event.ActionEvent; import javax.servlet.http.HttpServletRequest; public class Client { private Integer id_client; private String nom; private String prenom; String pilote = "com.mysql.jdbc.Driver"; HttpServletRequest request; ResultSet resultat; // ------------------ Constructors -------------------------------- public Client(){} public Client(Integer id, String nom, String prenom){ this.id_client = id; this.nom = nom; this.prenom = prenom; } //-----------getter setter -------------------------------- public Integer getId_client() { return id_client; } public void setId_client(Integer id_client) { this.id_client = id_client; } 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 void clientDetail(ActionEvent event){ UIParameter component = (UIParameter) event.getComponent().findComponent("editId"); //id que j'ai récuperé a partir du lien edit Integer id = Integer.parseInt(component.getValue().toString()); try{ Class.forName(pilote); Connection connexion = DriverManager.getConnection("Jdbc:mysql://localhost/base","root",""); Statement instruction = connexion.createStatement(); resultat = instruction.executeQuery("select * from client where id_client='"+id+"' "); } catch (Exception e){ System.out.println("erreur : "+e.getMessage()); } } }
Merci pour 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
15
16
17
18
19
20 <faces-config><navigation-rule> <from-view-id>/listerclient.jsp</from-view-id> <navigation-case> <from-outcome>editClient</from-outcome> <to-view-id>/editClient.jsp</to-view-id> </navigation-case> </navigation-rule> <managed-bean> <managed-bean-name>clientBean</managed-bean-name> <managed-bean-class>com.connexion.Client</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>clientListBean</managed-bean-name> <managed-bean-class>com.connexion.Connexion</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> </faces-config>
Partager