0

So I just want to get some Data from the Backend to the Frontend and show it to the user. The first part of this is working, I get the data to the Frontend but it wont show through ui:repeat, c:forEach or 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>

When loading the page, it uses the #{getData.loadCategoryList()} and my log shows me: found 3 Categories, but thats just it. The Table says only no records found. What am I doing wrong here?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ben
  • 1
  • set the value on datatable to 'categoryList' instead of method. Cause loadCategoryList is void. Or modify method to return the list of records found. – Manu AG May 12 '16 at 13:50
  • alread did that and still got nothing. – Ben May 13 '16 at 19:45

0 Answers0