Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to print rows in different colors in jsp

 
giri shetty
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the HTML/Javascript/CSS forum.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic