Question

i'm new in jsf and jpa, but i want to display all my records from a table in the db.

The datapage for displaying all records is accessible from my navigation.

<h:body>
    <h:form>
        <p:menu styleClass="left-navigation">
            <p:submenu label="Versand" >
                <p:menuitem value="Bargeld-Versand" action="createNewAblieferung"/>
                <p:menuitem value="Bargeld-Bestellung"/>
                <p:menuitem value="Wertpost-Versand"/>
            </p:submenu>
            <p:submenu label="Administration">
                <p:menuitem value="Bestellungen"/>
                <p:menuitem value="Ablieferungen" action="allAblieferungen"/>
                <p:menuitem value="User"/>
            </p:submenu>
        </p:menu>
    </h:form>
</h:body>

And this is the code of the datapage "allAblieferungen.xhtml" wich should display all records in a primefaces datatable.

<h:body>
    <ui:composition template="WEB-INF/template/master.xhtml">
        <ui:define name="content">
            <h:form>
                <p:dataTable var="abl" value="#{ablieferungPM.getAllAblieferungen()}">
                    <p:column headerText="ID">
                        <h:outputText value="#{abl.id}"
                    </p:column>
                    <p:column headerText="AblieferndeGS">
                        <h:outputText value="#{abl.ablieferdeGS}"
                    </p:column>
                    <p:column headerText="EmpfängerGS">
                        <h:outputText value="#{abl.empfaengerGS}"
                    </p:column>
                    <p:column headerText="Bemerkung">
                        <h:outputText value="#{abl.bemerkung}"
                    </p:column>
                    <p:column headerText="Summe">
                        <h:outputText value="#{abl.summe}"
                    </p:column>
                </p:dataTable>
            </h:form>
        </ui:define>
    </ui:composition>
</h:body>

My managed bean (ablieferungPM.java) provides all the methods for the ui, including the "getAllAblieferungen()" method for displaying all records of the table.

@EJB
    private AblieferungService service;

public List<Ablieferung> getAllAblieferungen() {
    return service.getAllAblieferungen();
}

the method calls the service from the stateless bean (AblieferungService.java). The service includes all the methods of the business logic and uses jpa for the database-access. "getAllAblieferungen()" collects the objects from my database

@PersistenceContext
    private EntityManager em;

public List<Ablieferung> getAllAblieferungen() {
    return em.createNamedQuery(Ablieferung.FIND_ALL, Ablieferung.class).getResultList();
}

to get all objects of the table, i use the query of my entity-class standing below

@NamedQueries({
@NamedQuery(name = Ablieferung.FIND_ALL, query = "SELECT a FROM Ablieferung a"),})

So, the problem is, that nothing, really nothing, happens by clicking the link "Ablieferung"! There is also no exception at the console of the glassfish... It is possible to insert new Objects into the database with the form on the first link of the navigation. This works fine, so the connection to the database should be ok!

Was it helpful?

Solution

Try the url attribute in the menuitem, in this case the action does a POST request.

<p:menuitem value="Ablieferungen" url="myPage?faces-redirect=true"/>

please check this> PrimeFaces navigation using MenuItem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top