Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 15960
    
  19

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: am i right ,nested forEach loop for the below scenario, Suggest me ASAP Thanks in Advance
 
Similar Threads
JSTL iteration over 2 or more items
Help iterating through ArrayList of an ArrayList in JSTL
c:forEach performance hit
Binding to multi-D array
Using Two ArrayLists For One Table