You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by James Flynn <ja...@yahoo.com> on 2005/11/11 16:31:42 UTC
foreach unavailable?
Hi All,
We're having a problem where we need to do a nested loop through our data
model, basically the page needs to display:
Name1
Address1
Address2
Name2
Address1
Address2
Name3
Address1
Address2
The model looks like this:
class Person {
String name;
List addresses;
}
So - if we could use h:outputText in nested foreach loops in JSTL it'd be
straightfoward. But this seems impossible:
http://www.onjava.com/pub/a/onjava/2004/06/09/jsf.html
So the way to do something like this in JSF seems to be to use a one-column
dataTable - but:
* The data table wouldn't format the address properly - we just need -br- tags
within each address, but they don't display without f:verbatim, which makes us
think this isn't the way you're supposed to do things..
* Does that mean we need to nest an inner dataTable to loop through the
addresses? Is that even possible? It seems wrong somehow...
I'd be willing to try and write a foreach-type custom component, but it seems
to me that such a thing should already exist??
This is a pretty simple and common thing we're trying to do - any tips on how
to do this in MyFaces or JSF in general would be greatly appreciated..
Kind regards,
James
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Re: foreach unavailable?
Posted by Mike Kienenberger <mk...@gmail.com>.
The easiest way to do this is with t:dataList in tomahawk.
It's basically a c:forEach written as a JSF component, or, to put it
another way, a dataTable with no rendering.
On 11/11/05, James Flynn <ja...@yahoo.com> wrote:
>
> Hi All,
>
> We're having a problem where we need to do a nested loop through our data
> model, basically the page needs to display:
>
>
> Name1
> Address1
> Address2
>
> Name2
> Address1
> Address2
>
> Name3
> Address1
> Address2
>
>
> The model looks like this:
>
> class Person {
> String name;
> List addresses;
> }
>
> So - if we could use h:outputText in nested foreach loops in JSTL it'd be
> straightfoward. But this seems impossible:
>
> http://www.onjava.com/pub/a/onjava/2004/06/09/jsf.html
>
> So the way to do something like this in JSF seems to be to use a one-column
> dataTable - but:
>
> * The data table wouldn't format the address properly - we just need -br- tags
> within each address, but they don't display without f:verbatim, which makes us
> think this isn't the way you're supposed to do things..
>
> * Does that mean we need to nest an inner dataTable to loop through the
> addresses? Is that even possible? It seems wrong somehow...
>
> I'd be willing to try and write a foreach-type custom component, but it seems
> to me that such a thing should already exist??
>
> This is a pretty simple and common thing we're trying to do - any tips on how
> to do this in MyFaces or JSF in general would be greatly appreciated..
>
> Kind regards,
> James
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>