aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How  to print rows in different colors in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How  to print rows in different colors in jsp" Watch "How  to print rows in different colors in jsp" New topic
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: 61417
    
  67

Moving to the HTML/Javascript/CSS forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to print rows in different colors in jsp