Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to print rows in different colors in jsp

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the HTML/Javascript/CSS forum.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic