webtier@glassfish.java.net

Re: [webtier] How to handle a list in JSF 2

From: Lincoln Baxter, III <lincolnbaxter_at_gmail.com>
Date: Sat, 2 Jan 2010 14:42:15 -0500

Ahh... good point.

I'm not sure there's a good way to do this. You could, however, look in to
extending the UIData class for use in the datatable value="" binding from
your backing bean. Perhaps providing some basic reflection-based property
discovery in order to properly iterate over fields in each entity.

--Lincoln

On Sat, Jan 2, 2010 at 1:52 PM, Celinio Fernandes <papouasied_at_yahoo.com>wrote:

> thanks for your help.
> Well, i have multiple entities in the result of my SELECT.
> My question is similar to this one in the Sun forum :
> http://72.5.124.102/thread.jspa?threadID=5397095&messageID=10763941
>
> Not sure how to properly handle a list that contains multiple entities.
> Any idea ?
>
>
> --- On *Sun, 1/3/10, Lincoln Baxter, III <lincolnbaxter_at_gmail.com>* wrote:
>
>
> From: Lincoln Baxter, III <lincolnbaxter_at_gmail.com>
> Subject: Re: [webtier] How to handle a list in JSF 2
> To: webtier_at_glassfish.dev.java.net
> Date: Sunday, January 3, 2010, 12:00 AM
>
>
> If I'm reading this correctly. #{item} is a List object. You could use
> another nested <ui:repeat> or another nested <h:dataTable> to iterate over
> the results (columns) of #{item}.
>
> I think your situation is that you're trying to display a multidimensional
> array with an uni-dimensional table.
>
> --Lincoln
>
> On Sat, Jan 2, 2010 at 12:55 PM, Celinio Fernandes <papouasied@yahoo.com<http://mc/compose?to=papouasied@yahoo.com>
> > wrote:
>
>> Hi,
>> I have what i believe is a simple question for those who are familiar with
>> JSF.
>> I am not too familiar so before digging any further in the documentation i
>> thought i'd ask here for advice.
>>
>> My problem is quite simple: I want to display in a table the result of a
>> JPQL query.
>> That query looks like this :
>> select a.name, b.title, b.age from table1 a, table2 b where a.id = b.id
>>
>> So it returns a "list of lists" that looks like this:
>> ((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN),
>>
>> If i store the result of that query in an ArrayList (myList) in my Managed
>> Bean, I can then do this in my XHTML page:
>>
>> <h:datatable value="#{myBean.myList}" var="item">
>> <h:column>
>> <h:outputText value="#{item}" />
>> </h:column>
>> </h:datable>
>>
>> That of course does not work.
>> First because it displays the listing in one column only whereas there are
>> 3 elements in each list. Secondly because item points to the list object,
>> not an element of the list.
>>
>> How do i do that in JSF 2 ? Maybe with EL ?
>>
>> Thanks for helping.
>>
>>
>>
>>
>
>