You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bOOyah <bo...@nowhere.org> on 2004/04/06 16:31:17 UTC
How can I display a table in two columns?
Hi all
I have a 2-column table containing 16 row items, each with an associated
checkbox. Right now I'm iterating over a List to render each row of the
table. Column 1 contains the checkboxes; column 2 contains the items.
So my table currently looks like this (x == a checkbox):
x item-1
x item-2
. . .
x item-16
Is there a straightforward way to iterate my List so as to render my
table as two columns (four columns really) of 8 rows each? Like this:
x item-1 x item-9
x item-2 x item-10
. . . . . .
x item-8 x item-16
Thanks!
--
bOOyah
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How can I display a table in two columns?
Posted by bOOyah <bo...@nowhere.org>.
Daniel Perry wrote:
> This works ok for that scenario, but what about if you need each item out of
> the list? eg, to iterate through a list of names:
>
> <logic:iterate name="names" id="name">
> <tr><td><bean:write name="name"/></td></tr>
> </logic:iterate>
>
> Gives one column....
>
> <tr><td>name1</td></tr>
> <tr><td>name2</td></tr>
> <tr><td>name3</td></tr>
> <tr><td>name4</td></tr>
>
> Is there an easy way to get:
>
> <tr><td>name1</td><td>name2</td></tr>
> <tr><td>name3</td><td>name4</td></tr>
The best I can come up with (shooting from the hip) is to create an
intermediate bean which contains two properties, the column-1 value and
the column-2 value. Populate each bean, put them in a list, then
iterate over that list. Something like this:
------------------------------------------------------------
List names = new ArrayList();
int i = 1;
while (i<=numItems) {
TwoColBean b = new TwoColBean();
b.setCol1("name" + i++);
b.setCol1("name" + i++);
this.names.add(b);
}
...
<c:forEach items="${names} var="name" >
<tr>
<td><c:out value="${name.col1}"/></td>
<td><c:out value="${name.col2}"/></td>
</tr>
</c:forEach>
------------------------------------------------------------
Surely there must be a tag lib somewhere that offers this?
--
bOOyah
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: How can I display a table in two columns?
Posted by Daniel Perry <d....@netcase.co.uk>.
This works ok for that scenario, but what about if you need each item out of
the list? eg, to iterate through a list of names:
<logic:iterate name="names" id="name">
<tr><td><bean:write name="name"/></td></tr>
</logic:iterate>
Gives one column....
<tr><td>name1</td></tr>
<tr><td>name2</td></tr>
<tr><td>name3</td></tr>
<tr><td>name4</td></tr>
Is there an easy way to get:
This would seem a fairly common scenario to me!
<tr><td>name1</td><td>name2</td></tr>
<tr><td>name3</td><td>name4</td></tr>
Daniel.
-----Original Message-----
From: news [mailto:news@sea.gmane.org]On Behalf Of bOOyah
Sent: 06 April 2004 20:47
To: user@struts.apache.org
Subject: Re: How can I display a table in two columns?
Axel Stahlhut wrote:
<snip/>
>> Is there a straightforward way to iterate my List so as to render my
>> table as two columns (four columns really) of 8 rows each? Like this:
>>
>> x item-1 x item-9
>> x item-2 x item-10
>> . . . . . .
>> x item-8 x item-16
>
> There are a lot of ways to reach what you need, but the following is the
> nicest, I think:
>
> <table>
> <logic:iterate: name="myBean" property="listProperty" index="id">
> <tr><td>
> <html:checkbox name="..." value="<%=whateverValue%>"/>
> </td><td>
> <html:checkbox name="..." value ="<%=whateverValue+8%>" />
> </td></tr>
> </logic:iterate>
> <table>
Thanks Axel. That would probably work fine. My list is always a fixed
size, but with variable content.
> By the way, what is the submitted value of the cb? Is it the index or
> some other kind of id?
The multibox values are actually IDs; database primary keys as it happens.
Thanks again!
--
bOOyah
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How can I display a table in two columns?
Posted by bOOyah <bo...@nowhere.org>.
Axel Stahlhut wrote:
<snip/>
>> Is there a straightforward way to iterate my List so as to render my
>> table as two columns (four columns really) of 8 rows each? Like this:
>>
>> x item-1 x item-9
>> x item-2 x item-10
>> . . . . . .
>> x item-8 x item-16
>
> There are a lot of ways to reach what you need, but the following is the
> nicest, I think:
>
> <table>
> <logic:iterate: name="myBean" property="listProperty" index="id">
> <tr><td>
> <html:checkbox name="..." value="<%=whateverValue%>"/>
> </td><td>
> <html:checkbox name="..." value ="<%=whateverValue+8%>" />
> </td></tr>
> </logic:iterate>
> <table>
Thanks Axel. That would probably work fine. My list is always a fixed
size, but with variable content.
> By the way, what is the submitted value of the cb? Is it the index or
> some other kind of id?
The multibox values are actually IDs; database primary keys as it happens.
Thanks again!
--
bOOyah
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How can I display a table in two columns?
Posted by Axel Stahlhut <as...@neusta.de>.
bOOyah wrote:
> Hi all
>
> I have a 2-column table containing 16 row items, each with an
> associated checkbox. Right now I'm iterating over a List to render
> each row of the table. Column 1 contains the checkboxes; column 2
> contains the items.
>
> So my table currently looks like this (x == a checkbox):
>
> x item-1
> x item-2
> . . .
> x item-16
>
>
> Is there a straightforward way to iterate my List so as to render my
> table as two columns (four columns really) of 8 rows each? Like this:
>
> x item-1 x item-9
> x item-2 x item-10
> . . . . . .
> x item-8 x item-16
>
>
> Thanks!
Hi.
There are a lot of ways to reach what you need, but the following is the
nicest, I think:
<table>
<logic:iterate: name="myBean" property="listProperty" index="id">
<tr><td>
<html:checkbox name="..." value="<%=whateverValue%>"/>
</td><td>
<html:checkbox name="..." value ="<%=whateverValue+8%>" />
</td></tr>
</logic:iterate>
<table>
|If the length of the list is dynamic, you have to first calculate the half and the offset to add etc. Furthermore you would then have tot
Regards Axel
|
By the way, what is the submitted value of the cb? Is it the index or
some other kind of id?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org