This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes How to set background color for records? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to set background color for records?" Watch "How to set background color for records?" New topic
Author

How to set background color for records?

Anand Nuchchi
Greenhorn

Joined: Apr 15, 2006
Posts: 27
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

Joined: Feb 15, 2005
Posts: 4864
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 ]

Merrill
Consultant, Sima Solutions
Anand Nuchchi
Greenhorn

Joined: Apr 15, 2006
Posts: 27
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

Joined: Feb 15, 2005
Posts: 4864
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
 
subject: How to set background color for records?
 
Similar Threads
Show - Hide Functionality
struts logic:iterate problem
Please help with pagination in JSP?
Help me about html:select
empty table cells