• 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

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

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what we used to display alternate rows with two different colors !


[ August 20, 2008: Message edited by: Sagar Rohankar ]
 
lavi mendonca
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 !!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!!

have you tried expression language and JSTL??


 
Fernando Almada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
upps...

 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic