aspose file tools*
The moose likes JSF and the fly likes am i right ,nested forEach loop for the below scenario, Suggest me ASAP   Thanks in Advance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "am i right ,nested forEach loop for the below scenario, Suggest me ASAP   Thanks in Advance" Watch "am i right ,nested forEach loop for the below scenario, Suggest me ASAP   Thanks in Advance" New topic
Author

am i right ,nested forEach loop for the below scenario, Suggest me ASAP Thanks in Advance

S.Reddisekhar Reddy
Greenhorn

Joined: Jan 05, 2012
Posts: 29
I have a scenario like one customer have list of orders,each list have list of Items
private Item item;
private ArrayList<Item> items;
private ArrayList orders;

I can iterate those like
for(int i=0;i<f1.getOrders().size();i++)
{
ArrayList l=(ArrayList)f1.getOrders();
for(int j=0;j<l.size();j++)
{
Item it=(Item)l.get(j);
System.out.println(it.getItemNo());
System.out.println(it.getItemName());
}

}
Can i display those in JSF using forEach loop like

<c:forEach items="#{bean.orders}" var="order">
<c:forEach items="#{order.items}" var="item">
<outputText value="#{item.itemNo}" />
<outputText value="#{item.itemName}" />
</c:forEach>
</c:forEach>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16243
    
  21

You will generally not enjoy what happens if you use JSTL with JSF. Fortunately, JSF has its own, better-integrated ways of doing the things that JSTL does.

Normally my recommendation when rendering a collection of objects in a JSF View is to use an h:dataTable element paired with a DataModel model support object. However, nested tables in JSF are not well supported.

One possibility would be to use a dataTable for the outer collection and a ui:repeat for the inner collection.

You can nest a dataTable within another dataTable, but since currently JSF has little support for retrieval of selected data from a nested DataModel, the code required to do so is not very pretty.


Customer surveys are for companies who didn't pay proper attention to begin with.
S.Reddisekhar Reddy
Greenhorn

Joined: Jan 05, 2012
Posts: 29
Thanks Tim Holloway
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: am i right ,nested forEach loop for the below scenario, Suggest me ASAP Thanks in Advance