Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
S.Reddisekhar Reddy
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
S.Reddisekhar Reddy
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim Holloway
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic