简体   繁体   English

用数据填充primefaces数据表

[英]Fill the primefaces datatable with data

i am using the primefaces(I use PF 3.5) datatable and I want to fill the table with data from my db. 我使用的primefaces(我使用PF 3.5) 的数据表 ,我想,以填补表从我的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. 但是,当我在我的xhtml页面中呈现表格时,我No records found. back. 背部。

I really appreciate your answer!!! 我非常感谢你的回答!

UPDATE 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 更新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();
}

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. value应该是一个可迭代的列表类型。

See the showcase: http://www.primefaces.org/showcase/ui/datatableBasic.jsf;jsessionid=1c0z4mgiaz5531cqf4v78m79iy 查看展示: http//www.primefaces.org/showcase/ui/datatableBasic.jsf; jsessionid = 1c0z4mgiaz5531cqf4v78m79iy

You can use @Juvanis solution, or in your chosen you need to use: 您可以使用@Juvanis解决方案,或者在您选择的时候使用:

 <p:dataTable var="product" value="#{productservice.getListOrderedByDate()}">

Instead of: 代替:

 <p:dataTable var="product" value="#{productservice.getListOrderedByDate}">

Are you sure the value attribute is correct? 你确定value属性是否正确?

In my opinion it should be 在我看来应该是

 value="#{productservice.listOrderedByDate}

and not 并不是

value="#{productservice.getListOrderedByDate}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM