PrimeFaces 5.3 Datatable获取数据但仅显示未找到的记录

时间:2016-05-12 13:43:52

标签: jsf jsf-2 primefaces datatable

所以我只想从后端到前端获取一些数据并将其显示给用户。第一部分是工作,我将数据提供给前端,但它不会通过ui显示:repeat,c:forEach或p:dataTable。

GetData.java

private List<Category> categoryList;

public List<Category> getCategoryList() {
    return categoryList;
}

public void loadCategoryList() {
    categoryList = getAllCategories().getCategoryList();
    System.out.println("LOAD: " + categoryList.size());
    System.out.println("GET: " + getCategoryList().size());
}

public void setCategoryList(List<Category> categoryList) {
    this.categoryList = categoryList;
}

public Categories getAllCategories() {
    Delegate delegate = new Delegate();
    Categories dto = delegate.getAllCategories();
    System.out.println(dto.getCategoryList().size());
    return dto;
}

Delegate.java

public Categories getAllCategories() {
    EntityManager em = getEntityManager();
    List<Category> categoryList = Logic.getAllCategories(em);
    Categories dto = new Categories(categoryList);
    closeEntityManager(em);
    return dto;
}

Logic.java

public static List<Category> getAllCategories(EntityManager em) {
    try{
        em.getTransaction().begin();
        List<Category> categoryList = em.createQuery(allCategories,Category.class).getResultList();
        em.getTransaction().commit();
        return categoryList;
    }
    catch(Exception e){
        System.out.println("Could not get all Categories! Error: " + e);
        return null;
    }
}

open.xhtml

<div class="site">
    <div id="main" class="content">
        <ui:include src="/old/templates/menu.xhtml" />
        <br />

        <div class="nav-table">
            <h:form id="nav-form">
                <p:dataTable id="nav-table" var="category" value="#{getData.loadCategoryList()}" rows="20">
                    <f:facet name="header">

                    </f:facet>
                    <p:row>
                        <p:column>
                            <p:commandLink actionListener="#{controller.setCurrentCategory(category)}" value="#{category.getName()}" />
                        </p:column> 
                    </p:row>
                    <f:facet name="footer">

                    </f:facet>          
                </p:dataTable>          
            </h:form>
        </div>

    </div>
</div>

加载页面时,它使用#{getData.loadCategoryList()},我的日志显示:找到3个类别,但就是这样。表中只显示没有找到记录。我在这里做错了什么?

0 个答案:

没有答案