0

I am so new to this that I do not even know what to search for to help look for an answer.

I have my list of Orders and each Order object and it contains a list of items. How do i properly display the name of each item inside each Order on a JSP?

This is my current code

DisplayOrders.xhtml

<ui:define name="body">
        <h:dataTable value="#{OrderController.allOrders}" var="order">
            <h:column>
                <!-- column header -->
                <f:facet name="header">Order #</f:facet>
                <!-- row record -->
                #{order.id}
            </h:column>
            <h:column>
                <!-- column header -->
                <f:facet name="header">Customer</f:facet>
                <!-- row record -->
                #{order.customer.firstName} #{order.customer.lastName}
            </h:column>
            <h:column>
                what do i put here!!!!!
            </h:column>
        </h:dataTable>
    </ui:define>

Order.java

private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate = new Date();

@ManyToMany
private List<Item>items = new ArrayList<>();

@ManyToOne
@JoinColumn(name = "CUSTOMER_FK")
private Customer customer;
public List<Item> getItems() {
    return items;
}

Item.java

protected String title;
public String getTitle(){
    return title;
}

public void setTitle(String title){
    this.title = title;
}

OrderController.java

//Just the getter I use in the JSP
public List<Orders> getAllOrders(){
    return orderEJB.getAllOrders();
}

OrderEJB.Java

public List<Orders> getAllOrders(){
    Query query = em.createNamedQuery("findAllOrders");
    List<Orders> cusList = query.getResultList();
    return cusList;
}

My question is this. What possible code do I put there to get the correct data? Because the following code does not work and I am out of ideas.

<h:dataTable value="#{order.items}" var="itm">
                    #{itm.title}
                </h:dataTable>
//or
#{order.items.get(0).title}
//or
<c:forEach items="#{order.items}" var="itm" >
                        #{itm.title}
                    </c:forEach>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Daedric
  • 1
  • 6
  • Don't you have also to iterate through your order list first? Because as i see from the code, the `order` variable is seen as a list, and to get all the items from a order you must refer to a `Order` object, not to `List` of `Orders` – drgPP Sep 29 '15 at 07:52
  • 1
    i tried that using a dataTable and a c:forEach to go through each. several things. however yes BalusC pointed it out there was another person who answered this. #{itm.title}
    – Daedric Sep 29 '15 at 13:59

0 Answers0