Reputation: 11514
i am using the primefaces(I use PF 3.5) datatable and I want to fill the table with data from my db.
<p:dataTable id="cars" var="car" value="#{productservice.getListOrderedByDate()}"
editable="true" editMode="cell" widgetVar="productTable">
my service method looks like that:
public List<Product> getListOrderedByDate() {
log.trace("Returning list of Products...");
log.info(productDAO.getProductsOrderedByDate());
return productDAO.getProductsOrderedByDate();
}
However, when I render the table in my xhtml
page I get No records found.
back.
I really appreciate your answer!!!
UPDATE
<p:dataTable var="product" value="#{productservice.getListOrderedByDate}">
<f:facet name="header"> Product </f:facet>
<p:column headerText="id" style="width:15%">
<h:outputText value="#{product.id}" />
</p:column>
<p:column headerText="Object Type" style="width:15%">
<h:outputText value="#{product.objectType}" />
</p:column>
<p:column headerText="Price" style="width:15%">
<h:outputText value="#" />
</p:column>
<p:column headerText="For" style="width:15%">
<h:outputText value="#{product.for}" />
</p:column>
UPDATE 2
my method product ordered by date:
public List<Product> getProductsOrderedByDate() {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Product> criteria = cb.createQuery(Product.class);
Root<Product> product = criteria.from(Product.class);
criteria.select(product).orderBy(cb.desc(product.get("creationDate")));
return em.createQuery(criteria).getResultList();
}
Upvotes: 1
Views: 8164
Reputation: 4189
You can use @Juvanis solution, or in your chosen you need to use:
<p:dataTable var="product" value="#{productservice.getListOrderedByDate()}">
Instead of:
<p:dataTable var="product" value="#{productservice.getListOrderedByDate}">
Upvotes: 2
Reputation: 506
Are you sure the value attribute is correct?
In my opinion it should be
value="#{productservice.listOrderedByDate}
and not
value="#{productservice.getListOrderedByDate}"
Upvotes: 0
Reputation: 25950
I guess the problem is that you set value in a wrong way.
value="#{yourBean.listOfCars}"
value is expected to be a iterable type of list.
See the showcase: http://www.primefaces.org/showcase/ui/datatableBasic.jsf;jsessionid=1c0z4mgiaz5531cqf4v78m79iy
Upvotes: 2