| Author |
How to print rows in different colors in jsp
|
giri shetty
Greenhorn
Joined: Jan 22, 2004
Posts: 27
|
|
Hi guys, i have a question ,i have a jsp using STRUTS an i have to print details in in row wise and i have to maintain a different color for each consicutive row . thanks
|
 |
Alan Ford
Ranch Hand
Joined: Oct 26, 2003
Posts: 107
|
|
|
what i did is: my backing page is extended with object for support of switching those colors. so it will return diferent string (the one(s) defined in css for both colors). So in my for loop I have tags that return different names (every second time till end of loop).
|
TNT<br />MCP, SCJP 1.4,
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56191
|
|
|
Moving to the HTML/Javascript/CSS forum.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
you can change the style of the row with <tr style="background:#C0C0C0"> If you are wrting out the rows with the server side code, then do a mod(%) check with the current row count and alternate the colors. There is a way to do it with JavaScript, but it is better to do it on the server side. Eric
|
 |
Julia Reynolds
Ranch Hand
Joined: May 31, 2001
Posts: 123
|
|
Here is some row alternating code from Ted Husted's Struts FAQ : <% int count=0; %> <struts:iterate id="row" name="currentReport" property="data" > <tr BGCOLOR='<%= (count++ % 2==0 ?"#FFFFAA":"#EEEEEE") %>' > <td> <%= count %> </td> <struts:iterate id="item" collection="<%= row %>" > <td nowrap align=MIDDLE > <%=(item).toString() %> </td> </struts:iterate> </tr> </struts:iterate>
|
 |
Julian Kennedy
Ranch Hand
Joined: Aug 02, 2004
Posts: 823
|
|
Folks should really embrace the 21st century and use CSS. HTML 3.2 is dead (or at least I wish it was!) I use class="odd" and class="even" for my alternating table rows and then include something like the following in the CSS file: A pretty yucky effect with those colours but, hey! If you crowbar that into Julia's scary Struts example you can really - um - strut your stuff! :roll: Jules
|
 |
 |
|
|
subject: How to print rows in different colors in jsp
|
|
|