wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts 1.1: Need help with logic:iterate and logic:equals tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1.1: Need help with logic:iterate and logic:equals tag" Watch "Struts 1.1: Need help with logic:iterate and logic:equals tag" New topic
Author

Struts 1.1: Need help with logic:iterate and logic:equals tag

lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
Hi,

I am using struts 1.1. I have an Arraylist on my formbean. Using logic:iterate tag, i am displaying the the contents of the Arraylist on the jsp. But at the same time, i need to show the alternate rows in different colors. e,g. First row (background) color should be in green, Second row (background) color should be in yellow, third row (background) color should be in green, and next row in yellow and so on.

I am using the mod function i.e counter%2 to identify odd row and even row using logic:equals tag, but this does not work.

The following is my code:

<logic:iterate id="users" name="searchForm" property="searchResultsUser" indexId="counter" >

<tr>

<logic:equal name="<%=counter.intValue()%2 %>" value="0">
<td class="greenRow"><bean:write name="users" property="firstName"/></td>
</logic:equal>

<logic:equal name="<%=counter.intValue()%2 %>" value="1">
<td class="yellowRow"><bean:write name="users" property="firstName"/></td>
</logic:equal>

</tr>

</logic:iterate>

How can i achieve the alternate colored row to diaplay my data in the list.
Any help would be greatly appreciated.

Thanks.
lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
I also tried to implement doing the below, but it did not work. It just enters the notEqual condition. When i output the value of counterStr using out.println, it is displaying correctly - either 0 or 1

<logic:iterate id="users" name="searchForm" property="searchResultsUser" indexId="counter" >

<tr>

<%
String counterStr = ""+counter.intValue()%2;
%>

<logic:equal name="<%=counterStr%>" value="0">
<td class="greenRow"><bean:write name="users" property="firstName"/></td>
</logic:equal>

<logic:notEqual name="<%=counterStr%>" value="0">
<td class="yellowRow"><bean:write name="users" property="firstName"/></td>
</logic:notEqual>

</tr>

</logic:iterate>
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

This is what we used to display alternate rows with two different colors !


[ August 20, 2008: Message edited by: Sagar Rohankar ]

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
Thanks Sagar, but we are now allowed to have the css modified. I have to necessarily use the css class greenrow and yellowrow. If in your code, it accepts a counter.intValue() % 2, why is it not working when i use it in my logic equals tag ??
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by lavi mendonca:
If in your code, it accepts a counter.intValue() % 2, why is it not working when i use it in my logic equals tag ??


No need to use logic:equal tag , simply follow wht I post , Here is some changes I suggest in you code



Try this first !
lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
Thanks Sagar for your help.

I will try this out, though i can use use this approach only after i get the go-ahead to use my css. As mentioned in my earlier post, i am only allowed to use the existing greenrow, yellowrow css.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by lavi mendonca:
i am only allowed to use the existing greenrow, yellowrow css.


Ok , but I`m emphasizing on approach , the color may be anything from 0-255(R,B,G) . If you can do this and get the things , you ll fined more easier to modify !!
Fernando Almada
Greenhorn

Joined: Aug 28, 2008
Posts: 4
Hi!!

have you tried expression language and JSTL??


Fernando Almada
Greenhorn

Joined: Aug 28, 2008
Posts: 4
upps...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 1.1: Need help with logic:iterate and logic:equals tag