0
votes

I want to make a rich:datagrid using 2 lists from my backing bean instead of one.

So instead of :

<rich:dataGrid columns="1" width="100%" value="#{MyBean.myList1}" var="listobj1" iterationStatusVar="it" elements="10">

I want :

<rich:dataGrid columns="1" width="100%" value="#{MyBean.myList1}, #{MyBean.myList2}" var="listobj1, listobj2" iterationStatusVar="it" elements="10">

Is this possible?

1
Do you just want to iterate over all values of myList1 and myList2? In that case I'd use MyBean.myUnion as value and have a getter that just says List l = new ArrayList(myList1); l.addAll(myList2); return l;. But your use of var confuses me - what do you expect it to do?mabi
Sorry about that, should probably specify why.Basically I have 2 Lists on the backing bean which are Lists of POJOs(List<myPojo>).Now all I want is to be able to reference attributes of the POJO in the datagrid.So basically I want to be able to add <h:outputText value="#{listObj1.name} : #{listObj2.name}"/> inside the datagrid.Vinc
Is there a 1:1 mapping between listObj1 and listObj2? In that case you'd probably be able to use a Map<pojo1,pojo2> and iterate over that. Though that's kind of a hassle with JSF, see stackoverflow.com/questions/8552804/… and stackoverflow.com/a/10934074/785663mabi
Hmm the map is a nice idea,but unfortunetly using a map wont work as I get these as lists and they can become quite long so converting them to a map will take long,which I am trying to avoid.Vinc

1 Answers

2
votes

Short answer: no, that's not possible because value must point to an Object (not a composite string).

Based on the fact that you only have those two lists and there seems to be a implicit mapping, I'd iterate over one and reference the other from the loop:

<rich:dataGrid columns="1" value="#{MyBean.myList1}" rowKeyVar="k" var="elem" elements="10">
  <h:outputText value="#{elem.name}: #{MyBean.myList2[k].name}" />
</rich:dataGrid>