将结果从查询拉入数据表

时间:2012-11-29 23:18:38

标签: java jsf java-ee datatable

我无法从查询中提取信息并将其放入dataTable。

我需要提取大于输入价格的图书条目。

我认为这部分有点工作,但是我需要将它排序到数据表中以便可以读取。 (让它看起来很漂亮)

我不明白我在哪里丢失代码?在查询中排序更多?或者我可以只访问信息并将其传入dataTable。

这是我的BookQueries.xhtml页面的样子,但它不起作用! :(

    <h:dataTable id="table1" value="#{bookController.findBookGreater()}" var="item"
                 border="1">
        <f:facet name="header">
            <h:outputText value="Book Query Results" />
        </f:facet>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Books" />
            </f:facet>
            <h:outputText value="#{book.title}" />
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Price" />
            </f:facet>
            <h:outputText value="#{book.price}" />
        </h:column>

    </h:dataTable>

在BookController.java类中,我有:

 public List<Book> findBookGreater() {
    return ejbFacade.findBookByPrice(bookPrice);
}

在BookFacade.java中我有:

    public List<Book> findBookByPrice(Integer bprice) {

EntityManager em = getEntityManager();
Query query = em.createNamedQuery("findBooksGreater");
query.setParameter("bookprice", bprice);
List resultList = query.getResultList();
return resultList;

}

感谢任何可以提供的帮助!!

1 个答案:

答案 0 :(得分:1)

您定义var="item"

<h:dataTable id="table1" value="#{bookController.findBookGreater()}" var="item"
             border="1">

因此,列表中的每个元素都会被称为item,但您尝试引用book

<h:outputText value="#{book.title}" />

改为使用

<h:outputText value="#{item.title}" />
相关问题