我是新手,我甚至不知道该搜索什么来帮助寻找答案。
我有我的订单列表和每个订单对象,它包含一个项目列表。如何在JSP上正确显示每个Order中每个项目的名称?
这是我目前的代码
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;
}
我的问题是这个。我可以用什么代码来获取正确的数据?因为以下代码不起作用,我没有想法。
<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>