aspose file tools*
The moose likes JSP and the fly likes Display table rows using JSTL with different colors based on condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Display table rows using JSTL with different colors based on condition" Watch "Display table rows using JSTL with different colors based on condition" New topic
Author

Display table rows using JSTL with different colors based on condition

namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
I need to display a table using jstl. The columns are id, tie_id, comments.
id is the primary key in table. I want to display rows having same tie_id with same color.
How can I write jstl loop for this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Assign a CSS class name to the <tr> element for the row that's distinct for each distinct value.

The class name can be used to assign different background colors.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
Each row tie_id may not be different. For example, first three rows will have same tie_id=1, next two will have same tie_id=2 etc.
I need to compare tie_id of each row using jstl.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Comparisons are easy; use the == (or eq) operator.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
How many different tie_id values might you have? 3? 47? 1023? 1048576?
If you're going to come up with a unique color for each unique tie_id, will you have enough colors?

Are the records going to be grouped by tie_id? If not, should they be?

If they are grouped by tie_id, then can't you just alternate colors between different sets of tie_id values, as in:
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
Thanks for your replies Mark and Bear. I don't know in future how many tie_id's will be there. So, I am going to repeat the colors. I have set color array of string in session having 10 colors. After the 10'th color, again the first color repeats and so on.
The records are grouped by tie_id. I have set following loop and getting error message. I am taking value of tie_id of first row=first_tieId and then compare it with tie_id of other records. If tie_id are different, a new color will be set.


Erroe Message : Unable to find a value for "1" in object of class "java.lang.String" using operator "[]"

Please help!
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
I am getting stuck because I am not able to access the color array in JSP which is in session scope.


Help!
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
How did you create this array and place it in the session scope (show the code that did this).
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
I got the answer. I just accessed it using ${sessionScope.color[i]} and it worked. Thanks again you all!!
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
namita sasa wrote:I got the answer. I just accessed it using ${sessionScope.color[i]} and it worked. Thanks again you all!!

Yes, but then you're setting another variable called color? Won't this be confusing?
Perhaps you could call one color_list?
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
When you do this:

You're basically hiding the session-scoped var with a page-scoped var (when you use unqualified access to color). Use a different name, like:
namita sasa
Ranch Hand

Joined: Apr 20, 2009
Posts: 56
Ok. I got what you said. I will change the names of page scope and session scope variables.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display table rows using JSTL with different colors based on condition