List within a List
What is the most efficient way of constructing a dataTable that has a List? For Example I need to construct this table (Order List):
Order #ProductsQuantity Status
12321prod1 10open
prod2 5
prod3 1
45681prodA 7closed
prodB 11
Basically the orderList returns a List of Orders. Each Order has a List of Products that has to be shown. I could use a dataTable for each Products and Quantity column but I would would like to know a much cleaner/faster way
Thank you
Steve
[532 byte] By [
javaBuffa] at [2007-11-26 16:34:24]

# 1
You can just nest datatables.
Also see http://balusc.xs4all.nl/srv/dev-jep-dat.html ?http://balusc.xs4all.nl/srv/dev-jep-dat.html#NestingDatatables
Basic example:
Order.javapublic class Order {
private Long id;
private List<Product> products;
private String status;
// + getters + setters
}
Product.javapublic class Product {
private String name;
private Integer quantity;
// + getters + setters
}
JSF<h:dataTable value="#{myBean.orders}" var="order">
<h:column><h:outputText value="#{order.id}" /></h:column>
<h:column>
<h:dataTable value="#{order.products}" var="product">
<h:column><h:outputText value="#{product.name}" /></h:column>
<h:column><h:outputText value="#{product.quantity}" /></h:column>
</h:dataTable>
</h:column>
<h:column><h:outputText value="#{order.status}" /></h:column>
</h:dataTable>
# 3
<h:dataTable value="#{myBean.orders}" var="order">
<h:column>
<f:facet name="header" value="Order #" />
<h:outputText value="#{order.id}" />
</h:column>
<h:column>
<f:facet name="header" value="Products" />
<h:dataTable value="#{order.products}" var="product">
<h:column>
<h:outputText value="#{product.name}" />
</h:column>
</h:dataTable>
</h:column>
<h:column>
<f:facet name="header" value="Quantity" />
<h:dataTable value="#{order.products}" var="product">
<h:column>
<h:outputText value="#{product.quantity}" />
</h:column>
</h:dataTable>
</h:column>
<h:column>
<f:facet name="header" value="Status" />
<h:outputText value="#{order.status}" />
</h:column>
</h:dataTable>
# 4
Thanks man.
This is exactly what I have done even before posting my question. The real form has 7 columns and each column has an embedded dataTable. It works fine and dandy, but the code looks kinda unoptimized since what we did here is to create a dataTable for each column.
I was hoping for a cleaner and shorter approach.