-3

I'm doing a project in JSF, and to test my project I made an interface and I used a managed bean to display the contents of an entity defined in the database in a simple page xhtml, i have already put the EJB to use the service, but nothing appears in the page test, page can you help me please.

Entity :

@Entity
@NamedQuery(name="Patient.findAll", query="SELECT p FROM Patient p")
public class Patient implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name="id_patient")
private int idPatient;

private String adresse;

@Temporal(TemporalType.TIMESTAMP)
@Column(name="date_naissance")
private Date dateNaissance;

private String email;

@Column(name="groupe_sanguin")
private String groupeSanguin;

private String login;

private String nom;

@Column(name="num_secu_sociale")
private String numSecuSociale;

private String password;

private String prenom;

@Column(name="regime_assurance")
private String regimeAssurance;

private String tel;

public Patient() {
}

public int getIdPatient() {
    return this.idPatient;
}

public void setIdPatient(int idPatient) {
    this.idPatient = idPatient;
}

public String getAdresse() {
    return this.adresse;
}

public void setAdresse(String adresse) {
    this.adresse = adresse;
}

public Date getDateNaissance() {
    return this.dateNaissance;
}

public void setDateNaissance(Date dateNaissance) {
    this.dateNaissance = dateNaissance;
}

public String getEmail() {
    return this.email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getGroupeSanguin() {
    return this.groupeSanguin;
}

public void setGroupeSanguin(String groupeSanguin) {
    this.groupeSanguin = groupeSanguin;
}

public String getLogin() {
    return this.login;
}

public void setLogin(String login) {
    this.login = login;
}

public String getNom() {
    return this.nom;
}

public void setNom(String nom) {
    this.nom = nom;
}

public String getNumSecuSociale() {
    return this.numSecuSociale;
}

public void setNumSecuSociale(String numSecuSociale) {
    this.numSecuSociale = numSecuSociale;
}

public String getPassword() {
    return this.password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getPrenom() {
    return this.prenom;
}

public void setPrenom(String prenom) {
    this.prenom = prenom;
}

public String getRegimeAssurance() {
    return this.regimeAssurance;
}

public void setRegimeAssurance(String regimeAssurance) {
    this.regimeAssurance = regimeAssurance;
}

public String getTel() {
    return this.tel;
}

@Override
public String toString() {
    return "Patient [idPatient=" + idPatient + ", adresse=" + adresse + ", dateNaissance=" + dateNaissance
            + ", email=" + email + ", groupeSanguin=" + groupeSanguin + ", login=" + login + ", nom=" + nom
            + ", numSecuSociale=" + numSecuSociale + ", password=" + password + ", prenom=" + prenom
            + ", regimeAssurance=" + regimeAssurance + ", tel=" + tel + "]";
}

public void setTel(String tel) {
    this.tel = tel;
}

}

ConsulterDossierInter (interface):

 @Remote
 public interface ConsulterDossierInter {

public List<Patient> getAllPatients();
public Patient findPatient(String nom);


 }

ConsulterDossier :

@Stateless
public class ConsulterDossier implements ConsulterDossierInter {


@PersistenceContext
private EntityManager em;



public ConsulterDossier() {
    // TODO Auto-generated constructor stub
}


@SuppressWarnings("unchecked")
@Override
public List<Patient> getAllPatients() {
    // TODO Auto-generated method stub
    Query query=em.createQuery("SELECT p FROM Patient p");
    return query.getResultList();
}

@Override
public Patient findPatient(String nom) {
    Query q=em.createQuery("SELECT p FROM Patient p WHERE p.nom=:nom");
    q.setParameter("nom",nom);
    return  (Patient) q.getSingleResult();
}

}

PatientBean :

 @ManagedBean
 @ViewScoped
 public class PatientBean implements Serializable{
 /**
 * 
 */
private static final long serialVersionUID = 1L;

@EJB
 ConsulterDossierInter consult_dossier;

private Patient patient= new Patient();

private List<Patient> list_patient=new  ArrayList<Patient>();

public List<Patient> listePatient(){
    list_patient=consult_dossier.getAllPatients();
    return list_patient;
}

@PostConstruct  
public void init(){
    list_patient=consult_dossier.getAllPatients();
}

public PatientBean() {
    // TODO Auto-generated constructor stub
}

public ConsulterDossierInter getConsult_dossier() {
    return consult_dossier;
}

public void setConsult_dossier(ConsulterDossierInter consult_dossier) {
    this.consult_dossier = consult_dossier;
}

public Patient getPatient() {
    return patient;
}

public void setPatient(Patient patient) {
    this.patient = patient;
}

public List<Patient> getList_patient() {
    return list_patient;
}

public void setList_patient(List<Patient> list_patient) {
    this.list_patient = list_patient;
}

}

and finally the xhtml interface index.xhtml :

<?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://xmlns.jcp.org/jsf/html"
  xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
  xmlns:f="http://xmlns.jcp.org/jsf/core">


<h:head>
 <title>
   test
   </title>
</h:head>
 <h:body>

    <h1>List of books</h1>

<h:dataTable id="booklist" 
             value="#{patientBean.list_patient}" 
             var="book" 
             border="1">

  <h:column>
    <f:facet name="header">
      <h:outputText value="Title"/>
    </f:facet>
    <h:outputText value="#{book.idPatient}"/>
  </h:column>

</h:dataTable>

  <hr/>

  <h:outputText value="TP3 from Beginning Java EE 7" style="font-style:    italic"/>
  </h:body>
  </html>

By the way i use GlassFish server 4.

Thanks

AmineBena17
  • 23
  • 1
  • 5
  • 1
    Split your problem in manageable parts. Start with a static list, does that work, then it is not jsf related. And using spring AND ejb is very uncommom. Then use a very simple entity, less code. Narrow down the problem, it is currently to broad – Kukeltje Jan 29 '17 at 14:46

1 Answers1

-2

1- Try to use Glassfish Payara (better than gf4) 2- Use Facade Pattern for your EJBs (better than @Remote interface) 3- replace spring tag with ejb

HichMAN
  • 37
  • 6
  • My ejb works correctly, i already test it in a simple main and it works, the problem persist in the jsf part on my project :/ – AmineBena17 Jan 29 '17 at 10:26
  • first you have some problems Bad practices in you mb; init your objects in @postConstruct and remove set of ejb, for your problem check if it called correctly; add outln in postconstruct – HichMAN Jan 29 '17 at 10:34
  • i change it, i still have nothing :( – AmineBena17 Jan 29 '17 at 10:49