probleme d'affichage "dataTable"
bonjour tout le monde , je suis débutante dans le monde des jsf et je suis amenée à réaliser un affichage de la table client en utilisant le composant "dataTable".
le probleme que j'ai apercu au niveau de l'execution c'est que la page est vide comme s'il y a aucun enregistrement au nivau de la table. (la table est pleine)
bon voila le code que j'ai réalisé:
Connexion.java
Code:
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
| package com.connexion;
import java.sql.*;
public class Connexion {
ResultSet resultat;
public ResultSet getResultat(){
String pilote = "com.mysql.jdbc.Driver";
try{
Class.forName(pilote);
Connection connexion = DriverManager.getConnection("Jdbc:mysql://localhost/base","root","");
Statement instruction = connexion.createStatement();
resultat = instruction.executeQuery("SELECT * FROM CLIENT");
while(resultat.next()){
System.out.println("---------------------------");
System.out.println("N° ID_CLIENT: "+resultat.getInt("id_client"));
System.out.println("NOM: "+resultat.getString("nom"));
System.out.println("PRENOM: "+resultat.getString("prenom"));
}
}
catch (Exception e){
System.out.println("echec pilote : "+e);
}
return this.resultat;
}
public void setResultat(ResultSet resultat){
this.resultat = resultat;
}
} |
Client.java
Code:
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
| package com.connexion;
import java.io.Serializable;
public class Client implements Serializable {
private Integer id_client;
private String nom;
private String prenom;
private String adresse;
private String tel;
// ------------------ Constructors --------------------------------
public Client(){}
public Client(Integer id, String nom, String prenom, String tel){
this.id_client = id;
this.nom = nom;
this.prenom = prenom;
this.tel = tel;
}
//-----------getter setter --------------------------------
public String getAdresse() {
return adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
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 String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public void setClient(Client c){
this.setId_client(c.getId_client());
this.setNom(c.getNom());
this.setPrenom(c.getPrenom());
this.setTel(c.getTel());
}
public Client getClient(){
return new Client(this.getId_client(),
this.getNom(),
this.getPrenom(),
this.getTel());
}
} |
listerclient.jsp
Code:
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
| <%@ page language="java" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<f:view>
<h:dataTable id="clients"
value="#{clientListBean.resultat}"
var="clients"
border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Nom"/>
</f:facet>
<h:outputText value="#{client.nom}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Prenom"/>
</f:facet>
<h:outputText value="#{client.prenom}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Adresse"/>
</f:facet>
<h:outputText value="#{client.adresse}" />
</h:column>
</h:dataTable>
</f:view>
</body>
</html> |
faces-config.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <faces-config>
<managed-bean>
<managed-bean-name>clientBean</managed-bean-name>
<managed-bean-class>com.connexion.Client</managed-bean-class>
<managed-bean-scope>request</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> |
Merci d'avance pour votre aide