0
votes

I was following this video tutorial of Getting Started with PrimeFaces Development in Java EE Applications.

https://netbeans.org/kb/docs/javaee/javaee-gettingstarted-pf-screencast.html

Everything was going smoothly until I got the “No records found” in my datatable at the end of the tutorial when there are records in the customer table.

My code for index.xhtml is listed down below.

<?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:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        Hello from Facelets
        <br />
        <h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />
        <br />
        <f:view>


            <h:form>
                <h1><h:outputText value="List"/></h1>
                <p:dataTable value="#{customerFacade.customers}" var="item" >
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="CustomerId"/>
                        </f:facet>
                        <h:outputText value="#{item.customerId}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Name"/>
                        </f:facet>
                        <h:outputText value="#{item.name}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Addressline1"/>
                        </f:facet>
                        <h:outputText value="#{item.addressline1}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Addressline2"/>
                        </f:facet>
                        <h:outputText value="#{item.addressline2}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="City"/>
                        </f:facet>
                        <h:outputText value="#{item.city}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="State"/>
                        </f:facet>
                        <h:outputText value="#{item.state}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Phone"/>
                        </f:facet>
                        <h:outputText value="#{item.phone}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Fax"/>
                        </f:facet>
                        <h:outputText value="#{item.fax}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Email"/>
                        </f:facet>
                        <h:outputText value="#{item.email}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="CreditLimit"/>
                        </f:facet>
                        <h:outputText value="#{item.creditLimit}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="DiscountCode"/>
                        </f:facet>
                        <h:outputText value="#{item.discountCode}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Zip"/>
                        </f:facet>
                        <h:outputText value="#{item.zip}"/>
                    </p:column>
                </p:dataTable>
            </h:form>
        </f:view>

    </h:body>
</html>

Any idea on where could be the problem? I found someone with same issues and tried his solution. However, it did not work.

(PrimeFaces DataTable "No records found" when there are records)

Any suggestions on how to resolve this problem?

Edit :

I have this in my CustomerFacade.java file

   public List<Customer> getCustomers()
    {
        return em.createNamedQuery("Customer.findAll").getResultList();
    }
1
By the way .. Thou shalt not do business logic in getter methods. I haven't reviewed that Netbeans video tutorial, but if it's really saying you to do so, I'd put that video in the trashbin and start with working through the resources and tutorials listed in our JSF wiki page stackoverflow.com/tags/jsf/info - BalusC

1 Answers

0
votes

Please make sure that your backed bean method getCustomers() returns a list of customers when envoked.