-
1. Re: Iterate two arraylist in one dataTable
damianharvey.damianharvey.gmail.com Mar 6, 2008 2:42 PM (in response to vikram.vikram.chhetry.gmail.com)Seems like you're inviting an indexOutOfBoundsException. If you're keen to do it you could always use the rowKeyVar from rich:dataTable; roughly something like this:
<rich:dataTable value="#{bean.arr1}" var="one" rowKeyVar="row"> <h:outputText value="#{one.property1}"/> <h:outputText value="#{bean.arr2[row -1]}"/>
Why don't you do some pre-processing in a Bean and merge the two lists into one logical list?
Cheers,
Damian.
-
2. Re: Iterate two arraylist in one dataTable
vikram.vikram.chhetry.gmail.com Mar 27, 2008 4:22 PM (in response to vikram.vikram.chhetry.gmail.com)<rich:dataTable value="#{bean.arr1}" var="one" rowKeyVar="row"> <h:outputText value="#{one.property1}"/> <h:outputText value="#{bean.arr2[row -1]}"/>
I tried this but it didnt work.
Can anyone help me out on this?I am badly stuck.
Thanks in advance.
-Vikram
-
3. Re: Iterate two arraylist in one dataTable
cremersstijn Mar 27, 2008 5:08 PM (in response to vikram.vikram.chhetry.gmail.com)Why don't you do it in the following way:
Merge the 2 list in the bean together like this:
public List getList(){ List newList = new ArrayList(); newList.addAll(arr1); newList.addAll(arr2); }
and in the view (xhtml page):
<rich:datatable value=#{bean.list} var="item"> <h:column> #{item.value} </h:column> </rich:datatable>
greetz
-
4. Re: Iterate two arraylist in one dataTable
vikram.vikram.chhetry.gmail.com Mar 27, 2008 5:19 PM (in response to vikram.vikram.chhetry.gmail.com)both my arraylist is of same size but contains diffrent entity objects.
arr1 contains objects of entity A
arr2 contains objects of entity B
is it still possible to merge it into 1?
how will the resulting arraylist look like if i merge them into 1?
Thanks for your reply
-Vikram
-
5. Re: Iterate two arraylist in one dataTable
vikram.vikram.chhetry.gmail.com Mar 27, 2008 5:23 PM (in response to vikram.vikram.chhetry.gmail.com)One thing more
i want to iterate both simultaneously.
Which is not possible if I merge them into 1 i suppose.
-Vikram
-
6. Re: Iterate two arraylist in one dataTable
nathandennis Mar 27, 2008 6:48 PM (in response to vikram.vikram.chhetry.gmail.com)store an index field in one of the list in addition to the other information (extend the entity with another class adding a field for every entity object). inject both list so that their components can be reference directly from jsf. then in the datatable, iterate through the extended component list and reference any components in the second list by simply passing it the index.
that should get your simultaneous iterating working. i think i have done this a couple places in the past.
-
7. Re: Iterate two arraylist in one dataTable
nathandennis Mar 27, 2008 6:52 PM (in response to vikram.vikram.chhetry.gmail.com)one more thing..
you better test the data set logically to make sure you have the correct number of objects in each before you go to iterating... or very bad things could happen,,, as damian said..
-
8. Re: Iterate two arraylist in one dataTable
nathandennis Mar 27, 2008 6:55 PM (in response to vikram.vikram.chhetry.gmail.com)i just had a better idea still...
create an int array the size of the two list if they are the same...
reference that array as the var.
then reference the components of each list directly. no extending the entity..i dont think i have done this,, but it should work.
-
9. Re: Iterate two arraylist in one dataTable
vikram.vikram.chhetry.gmail.com Mar 27, 2008 7:32 PM (in response to vikram.vikram.chhetry.gmail.com)
then reference the components of each list directly.How do i do this?
I don't know the exact syntax for this.
Thanks for your replies.
-Vikram
-
10. Re: Iterate two arraylist in one dataTable
mail.micke Mar 27, 2008 7:57 PM (in response to vikram.vikram.chhetry.gmail.com)Here's another suggestion for the pile
I'd just create a simple Wrapper objects... probably.
public List<WrapperObject> getTheList(){ if(theList == null){ //check list lengths //iterate over both list creating "theList" //with WrapperObjects } return theList; } //could be an inner class public class WrapperObject private A entityA; private B entityB; public WrapperObject(A a, B b){ entityA =a; entityB =b; } //gettters
-
11. Re: Iterate two arraylist in one dataTable
nathandennis Mar 28, 2008 12:33 AM (in response to vikram.vikram.chhetry.gmail.com)so you have your two result sets...
move them the two you want to reference directly to ArrayList
ArrayList list1 = ArrayList<YourEntityForList1> resultlist1; ArrayList list2 = ArrayList<YourEntityForList2> resultlist2; if(list1.size() == list2.size()) for(statement for building the arraylist of ints length of list1.size() with sequence index moved in to the array) aka resultlength and field index getters & setters for all
in the jsf jsp whatever your poisen
<h:datatable value="#{yourSessionBean.resultlength}" var="r"> ... <h:outputText value="#{yourSessionBean.list1.get(r.index).yourFieldFromEntityToDisplay}"/>
same for list2 in the same iteration. HTH
-
12. Re: Iterate two arraylist in one dataTable
sburgula1 Apr 7, 2010 10:26 PM (in response to vikram.vikram.chhetry.gmail.com)Can someone let me know how to iterate through multiple lists using a rich:dataGrid.