File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set background color for records?

 
Anand Nuchchi
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • 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 <cut> tag.
[ November 06, 2006: Message edited by: Merrill Higginson ]
 
Anand Nuchchi
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic