• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How to set background color for records?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Am planning to display the records from the database using struts frame work.
The odd number rows should be with bgcolor="#99FFCC" and even number rows should be in bgcolor="#99CC99".
Means the records should be displayed in alternative colors.

And my code will golike this....
"
<logic:iterate id="av1" name="anandagentprop">
<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFCC">
<tr>
<td width="24%" scope="col"><div align="right"><bean:write name="av1" property="propertytype"/></div></td>
<td width="27%" scope="col"><div align="right"><bean:write name="av1" property="postedby"/></div></td>
<td width="27%" scope="col"><div align="right"><bean:write name="av1" property="posteddate"/></div></td>
<td width="22%" scope="col"><div align="right"><bean:write name="av1" property="details"/></div></td>
</tr>

</table>
</logic:iterate>
"


---
Thanks in advance
Anand
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your application supports JSP 2.0 (Tomcat 5) you can do the following:


If you're using an earlier version of the JSP spec (Tomcat 4) you will have to surround the EL expression with a <c:out> tag.
[ November 06, 2006: Message edited by: Merrill Higginson ]
 
Anand Nuchchi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,

Thanks for the reply.
Ya i tried with your code but in output JSPpage it still shows the code,
Like "${((index % 2) == 0) ?" and the bgcolor working fine.
And i checked in the code it shows "Invalid text String".

And its compatible with JSP 2.0.
Will you please help me out in finding the solution.

Thanks ....
Anand.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, the <table> and </table> tags need to be outside the <logic:iterate> stanza.

It looks like there was an error in the code that I gave you. JSTL can't handle quotes within quotes, so I'd suggest removing the double quotes from the EL Expression so that it reads like this:


This makes the <tr> tag not strictly according to the rules of HTML, but IE, Firefox and most other browsers will forgive this.

If you want your HTML to be strictly correct, you can use the <c:choose> tag like this:


[ November 07, 2006: Message edited by: Merrill Higginson ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic