Bonsoir ,

Après l'implémentation de toutes les choses ,j'obtiens une page vide avec rien d'afficher dans ma table ?

A noter , que la table client possède bien des données.

Page 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
<?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">
    <h:head>
        <title>Les Clients</title>
    </h:head>
    <h:body>
 
        <f:view>
            <h:form>
                <h1><h:outputText value="List"/></h1>
                <h:dataTable value="#{customerMBean.customers}" var="item">
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Ncli"/>
                        </f:facet>
                        <h:outputText value="#{item.ncli}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Nom"/>
                        </f:facet>
                        <h:outputText value="#{item.nom}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Adresse"/>
                        </f:facet>
                        <h:outputText value="#{item.adresse}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Localite"/>
                        </f:facet>
                        <h:outputText value="#{item.localite}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Cat"/>
                        </f:facet>
                        <h:outputText value="#{item.cat}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Compte"/>
                        </f:facet>
                        <h:outputText value="#{item.compte}"/>
                    </h:column>
                </h:dataTable>
            </h:form>
        </f:view>
 
 
    </h:body>
</html>
Managed bean

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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JSF;
 
import Client.CustomerManager;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import serveur.Client;
 
/**
 *
 * 
 */
@Named(value = "customerMBean")
@SessionScoped
public class CustomerMBean implements Serializable {
 
    @EJB
    private CustomerManager customerManager;
    private Client client;
    private List<Client> clients;
 
    /**
     * Creates a new instance of CustomerMBean
     */
    public CustomerMBean() {
    }
 
    public List<Client> getCustomers() 
    {
      return customerManager.getAllCustomers();
    }
 
    public Client getClient() { return client; }
 
    public String showDetail(Client client) 
    {
      this.client = client;
      return "CustomerDetails";
    }
 
    public String update() 
    {
        client = customerManager.update(client);
        return "CustomerList";
    }
 
    public String list()
    {
        return "CustomerList";
    }       
 
 
}
Session bean

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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Client;
 
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import serveur.Client;
 
/**
 *
 * 
 */
@Stateless
@LocalBean
public class CustomerManager {
 
    @PersistenceContext(unitName = "TP1CustomerApplication-ejbPU")
    private EntityManager em;
 
    public List<Client> getAllCustomers() {
        return em.createNamedQuery("Client.findAll").getResultList();
    }
 
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
    public Client update(Client client) {
        return em.merge(client);
    }
 
    public void persist(Object object) {
        em.persist(object);
    }
 
 
}
Entity bean

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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package serveur;
 
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
 
/**
 *
 * 
 */
@Entity
@Table(name = "CLIENT")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Client.findAll", query = "SELECT c FROM Client c"),
    @NamedQuery(name = "Client.findByNcli", query = "SELECT c FROM Client c WHERE c.ncli = :ncli"),
    @NamedQuery(name = "Client.findByNom", query = "SELECT c FROM Client c WHERE c.nom = :nom"),
    @NamedQuery(name = "Client.findByAdresse", query = "SELECT c FROM Client c WHERE c.adresse = :adresse"),
    @NamedQuery(name = "Client.findByLocalite", query = "SELECT c FROM Client c WHERE c.localite = :localite"),
    @NamedQuery(name = "Client.findByCat", query = "SELECT c FROM Client c WHERE c.cat = :cat")})
public class Client implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 8)
    @Column(name = "NCLI")
    private String ncli;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 18)
    @Column(name = "NOM")
    private String nom;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 24)
    @Column(name = "ADRESSE")
    private String adresse;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "LOCALITE")
    private String localite;
    @Size(max = 2)
    @Column(name = "CAT")
    private String cat;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 16777215)
    @Column(name = "COMPTE")
    private String compte;
 
    public Client() {
    }
 
    public Client(String ncli) {
        this.ncli = ncli;
    }
 
    public Client(String ncli, String nom, String adresse, String localite, String compte) {
        this.ncli = ncli;
        this.nom = nom;
        this.adresse = adresse;
        this.localite = localite;
        this.compte = compte;
    }
 
    public String getNcli() {
        return ncli;
    }
 
    public void setNcli(String ncli) {
        this.ncli = ncli;
    }
 
    public String getNom() {
        return nom;
    }
 
    public void setNom(String nom) {
        this.nom = nom;
    }
 
    public String getAdresse() {
        return adresse;
    }
 
    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }
 
    public String getLocalite() {
        return localite;
    }
 
    public void setLocalite(String localite) {
        this.localite = localite;
    }
 
    public String getCat() {
        return cat;
    }
 
    public void setCat(String cat) {
        this.cat = cat;
    }
 
    public String getCompte() {
        return compte;
    }
 
    public void setCompte(String compte) {
        this.compte = compte;
    }
 
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ncli != null ? ncli.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 Client)) {
            return false;
        }
        Client other = (Client) object;
        if ((this.ncli == null && other.ncli != null) || (this.ncli != null && !this.ncli.equals(other.ncli))) {
            return false;
        }
        return true;
    }
 
    @Override
    public String toString() {
        return "serveur.Client[ ncli=" + ncli + " ]";
    }
 
}
Merci , du coup de main.