dataTable primefaces甚至是空数据

时间:2018-01-10 14:54:07

标签: primefaces

我在primefaces中的新功能你能帮助我吗?我希望通过mysql数据库表名称的数据来填充dataTable primefaces是产品

我得到了豆产品如下:

package ma.supmti.jsf.model;
import java.util.Date;
public class Product {
  private Integer id;
  private String name;
  private Integer prixAchat;
  private Integer prixVente;
  private Date dateCreation;

 public Product() {
 }
public Integer getId() {
    return id;
}
public void setId(Integer id) {
    this.id = id;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public Integer getPrixAchat() {
    return prixAchat;
}
public void setPrixAchat(Integer prixAchat) {
    this.prixAchat = prixAchat;
}
public Integer getPrixVente() {
    return prixVente;
}
public void setPrixVente(Integer prixVente) {
    this.prixVente = prixVente;
}
public Date getDateCreation() {
    return dateCreation;
}
public void setDateCreation(Date dateCreation) {
    this.dateCreation = dateCreation;
   }
}

将managedBean ServiceProduct作为服务

package ma.supmti.jsf.service;
import java.util.List;  
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import ma.supmti.jsf.dao.DAOProduct;
import ma.supmti.jsf.dao.IDAOProduct;
import ma.supmti.jsf.model.Product;

@ManagedBean(name = "serviceProduct")
@ApplicationScoped
public class ServiceProduct implements IServiceProduct {
IDAOProduct dao = new DAOProduct();
public ServiceProduct() {
}
public void addProduct() {
    dao.addProduct();   
}
public List<Product> selectProduct() {
    return dao.selectProduct();
}

}

Product ManagedBean:

package ma.supmti.jsf.presentation;

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import ma.supmti.jsf.model.Product;
import ma.supmti.jsf.service.ServiceProduct;

@ManagedBean(name="productM")
@ApplicationScoped
public class ProductMB implements Serializable {
   private static final long serialVersionUID = 1L;
   private List<Product> produits;

   @ManagedProperty("#{serviceProduct}")    
   private ServiceProduct srvProduct;

   @PostConstruct
   public void init() {
   setProduits(srvProduct.selectProduct());
  }


   public void setSrvProduct(ServiceProduct srvProduct) {
      this.srvProduct = srvProduct;
    }
   public List<Product> getProduits() {
    return produits;
   }
   public void setProduits(List<Product> produits) {
    this.produits = produits;
   }
}

和hibernate dao从mysql数据库加载数据

package ma.supmti.jsf.dao;
import org.hibernate.query.Query;
import ma.supmti.jsf.model.Product;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class DAOProduct implements IDAOProduct {

   public DAOProduct() {
}
public void addProduct() {
}
public List<Product> selectProduct() {
    Configuration config = new Configuration();
    config=config.configure("hibernate.cfg.xml");
    SessionFactory  sessionFactory = config.buildSessionFactory();
    Session session = sessionFactory.openSession();
    Query query = session.createQuery("from Product");
    List<Product> produits = query.list();
    for(Product produit:produits) {
        System.out.println("prix "+produit.getPrixAchat());
        System.out.println("Prenom "+produit.getPrixVente());
    }
    return produits;
     }

   }

这里是我要显示的dataTable

<?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 xlmns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui" 
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
  <title>LISTE DES PRODUITS </title>
  <style type="text/css">
body {
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-size: 14px;
   }
.header {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 18px;
}
.bottom {
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 9px;
 text-align: center;
 vertical-align: middle;
 color: #8E969D;
  }
 </style>
 </h:head>
 <body bgcolor="#ffffff">
    <p:dataTable  value="#{ProductM.produits}" var="produit" id="produit"                                   lazy="true" paginator="true" rows="10">
   <f:facet name="header">
        Liste des produits .....................
   </f:facet>
     <p:column headerText="Id">
        <h:outputText value="#{produit.id}" />
     </p:column>
     <p:column headerText="Name">
        <h:outputText value="#{produit.name}" />
    </p:column>
    <p:column headerText="Prix Achats">
        <h:outputText value="#{produit.prixachat}" />
    </p:column>
    <p:column headerText="Prix Vente">
        <h:outputText value="#{produit.prixvente}" />
    </p:column>
    <p:column headerText="Date Creation">
        <h:outputText value="#{produit.datecreation}" />
    </p:column>
   </p:dataTable> 
   </body>
  </html>

谢谢你的帮助

0 个答案:

没有答案