0

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();
    }
Community
  • 1
  • 1
Lawrence Wong
  • 1,129
  • 4
  • 24
  • 40
  • 2
    By the way .. [Thou shalt not do business logic in getter methods](http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times/2090062#2090062). 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 http://stackoverflow.com/tags/jsf/info – BalusC Aug 15 '14 at 15:29

1 Answers1

0

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

A. Shaheen
  • 105
  • 13
  • Hi there, getCustomers() returns a list of customers when envoked. Please see my updated code above. Any solutions? Thanks! – Lawrence Wong Aug 15 '14 at 15:22
  • Uhm, did you confirm that the method is invoked and that the list is not empty? Just put a debug breakpoint or add a poor man's `System.out.println(customers)` line. This way you can easily exclude if the problem is in JPA or in JSF and then reformulate the question if necessary. – BalusC Aug 15 '14 at 15:28
  • Ok. This is super weird. I try putting a debug breakpoint and did a step in and stuff... The System.out.println got invoked. And the data customer got displayed. I tried running it again and the customer data is now showing perfectly. I have no idea where the problem is... =.=' – Lawrence Wong Aug 15 '14 at 15:35
  • 1
    Apparently rebuild/redeploy/restart failed or hasn't even taken place. – BalusC Aug 15 '14 at 17:29