0

I've got a list of orders on a database, and I want to show two separate datatables in two JSF pages: one table regarding all orders, and one table regarding the current logged user. Problem is, only the first one is actually showed on the page.

JSF page with the datatable links

<h:commandLink action="#{ordineController.listaOrdini}"
        value="Consulta gli ordini esistenti" rendered="#{not empty loginAdmin.admin.email}"/>
    <div>
        <h:commandLink
            action="#{ordineController.listaOrdiniCliente}"
            value="Controlla i tuoi ordini"
            rendered="#{not empty loginCliente.clienteLoggato.email}">
            <f:setPropertyActionListener target="#{ordineController.clienteCorrente}"
                value="#{loginCliente.clienteLoggato}" />
        </h:commandLink>
</div>

ViewScoped bean

     @ManagedBean(name="ordineController")
@ViewScoped
public class OrdineController implements Serializable {

/**
     * 
     */
    private static final long serialVersionUID = 1L;
    @PostConstruct
    public void init() {
        ordini = oFacade.getListaOrdini();
        listaOrdiniCliente();
    } 
    public String listaOrdini() {
        this.ordini = oFacade.getListaOrdini();
        return "showOrdini"; 
    }

    public String listaOrdiniCliente() {
        this.ordiniCliente = oFacade.getOrdiniCliente(clienteCorrente);
        return "showOrdiniCliente"; 
    }
/*Getters and setters*

The JSF page that doesn't work (showOrdiniCliente.xhtml)

<h:outputText value="Non c'è nessun ordine."
        rendered="#{empty ordineController.ordiniCliente}" />
    <h:dataTable id="lista" value="#{ordineController.ordiniCliente}"
        var="ordine" rendered="#{not empty ordineController.ordiniCliente}">

The JSF page that does work (showOrdini.xhtml)

<h:outputText value="Non c'è nessun ordine."
    rendered="#{empty ordineController.ordini}" />
<h:form rendered="#{not empty ordineController.ordini}">
    <h:dataTable id="lista" value="#{ordineController.ordini}"
        var="ordine">

Why is the #{ordineController.ordiniCliente} empty? Shouldn't it be builded along with the "ordini" variable in the @PostConstruct?

edit Facade method (it retrieves all the orders of a customer)

public List<Ordine> getOrdiniCliente (Cliente cliente) {

    try {
        TypedQuery<Ordine> q = em.createQuery("SELECT ord FROM Ordine ord WHERE ord.cliente = :cliente", Ordine.class);
        q.setParameter("cliente", cliente);
        return q.getResultList();

    } 
    catch (Exception e) {
        String q = "Il cliente " +cliente.getNickname()+ " non ha creato degli ordini";
        System.out.println(q);
        return null;

    }

}
Enduavon
  • 39
  • 11
  • On a side note not related to problem PLEASE don't call backing beans `Controller`. JSF backing beans are not Controllers but Model in MVC. – Shahzeb Jun 10 '15 at 00:38
  • Please post full code for `OrdineController `. Have you put a breakpoint in `listaOrdiniCliente` to confirm that it is actually getting values from backend? Why is this method return `return "showOrdiniCliente"` are you trying to navigate away. – Shahzeb Jun 10 '15 at 00:45
  • 1
    @Shahzeb: Depends on point of view and how you create your beans. See also a.o. http://stackoverflow.com/questions/5104094/what-components-are-mvc-in-jsf-mvc-framework In OP's case, the `ordini`, `ordiniCliente` and `oFacade` are clearly the models. – BalusC Jun 10 '15 at 07:42
  • OrdineController doesn't have any other methods. Btw (sorry for the delay of my reply), I added the code for the facade method in the first post. Still can't view the list ordiniCliente in my page. @BalusC I'd love your help :D – Enduavon Jun 12 '15 at 18:59

0 Answers0