Board index JavaServer Faces General dataTable... No records found.

dataTable... No records found.

Components, Ajax Framework, Utilities and More.

Post 09 May 2011, 16:26

Posts: 1

I am new to primefaces and I need some help.

I want to create a simple application with a database connection.
I use dataTable component to list things from a table.
I have this message: "No records found." when I run my project.
I use NetBeans 7, PrimeFaces 2.2.1, MySQL 5 and Tomcat 7.

I have this code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""   
        <p:dataTable value="#{customerBean.getCustomerList()}" var="c">
                    <f:facet name="header">
                Customer ID
             <h:outputText value="#{c.customerID}"/>
             <f:facet name="header">
             <h:outputText value="#{}"/>
             <f:facet name="header">
             <h:outputText value="#{c.address}"/>
             <f:facet name="header">
                Created Date
             <h:outputText value="#{c.created_date}"/>
package oribase;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.util.Date;

public class Customer {
    public long customerID;
    public String name;
    public String address;
    public Date created_date;

    public String getAddress() {
        return address;

    public void setAddress(String address) {
        this.address = address;

    public Date getCreated_date() {
        return created_date;

    public void setCreated_date(Date created_date) {
        this.created_date = created_date;

    public long getCustomerID() {
        return customerID;

    public void setCustomerID(long customerID) {
        this.customerID = customerID;

    public String getName() {
        return name;

    public void setName(String name) { = name;

package oribase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.sql.DataSource;

public class CustomerBean implements Serializable{
        //resource injection
   private DataSource ds;
        //connect to DB and get customer list
   public List<Customer> getCustomerList() throws SQLException{
      throw new SQLException("Can't get data source");
                //get database connection
      Connection con = ds.getConnection();
      throw new SQLException("Can't get database connection");
       PreparedStatement ps = con.prepareStatement("select customer_id, name, address, created_date from customer");
                //get customer data from database
      ResultSet result =  ps.executeQuery();
       List<Customer> list = new ArrayList<Customer>();
         Customer cust = new Customer();
                        //store all data into a List
       return list;

Can anyone tell me where my code is wrong and why I get this message?

Posts: 39
Try to make your list private and make getters/setters for it. I think this is your issue.

First put some records in the list by hand and/or make sure your list is populated.

Posts: 20
Try changing this:
<p:dataTable value="#{customerBean.getCustomerList()}" var="c">

with this:
<p:dataTable value="#{customerBean.customerList}" var="c">

Return to General