• 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

Coloring Table Rows

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using jstl to build a table into my html page. One of the columns contains a priority number. I use javascript to read this number(innerHTML) and turn the rows specific colors. Is there a way to hide the column that I am using for priority. It does not affect anything just looks odd and really no need to display.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why wait until JavaScript can do it? Sounds like it'd be better handled in the JSP.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Why wait until JavaScript can do it? Sounds like it'd be better handled in the JSP.



Is there any way you can give some help on the correct coding.

Here is my jstl code There is a tenth array element(last column in table) no header exists for it. It is the coulmn that holds value I need to set row color:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First things first. You are mixing scriptlets with JSTL. What's up with that? That's a recipe for disaster and just plain messy.

Why do you feel the need to resort to scriptlets? <c:set> will allow you to set and change scoped values. Also <c:forEach> can provide loop counts and indexes.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:First things first. You are mixing scriptlets with JSTL. What's up with that? That's a recipe for disaster and just plain messy.

Why do you feel the need to resort to scriptlets? <c:set> will allow you to set and change scoped values. Also <c:forEach> can provide loop counts and indexes.



Can you elaborate a little on how to change the scriptlet code to achive what I need. I got this example from some else. I have used it a lot and seems to work. But I am always looking for better solutions.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Steve,
While iterating if you got the required value in that column, add simply the following code.
========
%>
<script>document.getElementById('<%=y%>').style.display = none;</script>
<%
========
Here what I am doing is, closing the jsp scriptlet and adding a javascript code to hide the row.

Hope this works.

Regards,
Y. Keerthi Sagar.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To me that seems like an extremely round-about way to put a style="display:none" attribute on a TD tag. Why wouldn't you just plain put that attribute on the tag in the JSP?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Keerthi Sagar wrote:Hi Steve,
While iterating if you got the required value in that column, add simply the following code.
========
%>
<script>document.getElementById('<%=y%>').style.display = none;</script>
<%
========
Here what I am doing is, closing the jsp scriptlet and adding a javascript code to hide the row.

Hope this works.

Regards,
Y. Keerthi Sagar.




Why would you use JavaScript to hide it like that? Just add the style attribute to it with display none. DOing it with JavaScript is bad for performance of the initial page load and it just looks fugly.

Eric
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So now I have got the scriptlet code out of my JSTL code. How do I color the current row I am in based on the value of the last element of my foreach item?

This is what I have so far. in this condition I want to turn the row background red:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either write the style attribute on the <tr> element, or assign it to a CSS class name that colors it.

Basically, you need to decide what the HTML should look like, and then make the JSP generate that.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Either write the style attribute on the <tr> element, or assign it to a CSS class name that colors it.



Will I use js to do that or is there another way after the <TR> tag hs been initialized to reference it with in the c:when tag?

Here is what I am attempting but getting an error "Object Required":

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NO JS! Just do it on the server. You have all the data there at your fingertips.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:NO JS! Just do it on the server. You have all the data there at your fingertips.



Ok how do I get a referance to the current row that my JSTL is processing like I do in the js?

 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem is obscured by a whole lot of diversions, but I think your question is this:

"I am generating a <tr> tag, and I want to set an attribute on this tag which makes the row be a certain colour, but I don't know what that colour is until after I have generated a whole lot more tags. So how do I set that attribute?"

Well, if it were me, I would do some more work in the part of your code (presumably it's a servlet) which puts information into the request context. Have it put the colour in a place where it's immediately accessible when you generate the TR tag.

Looks to me like you have put a list "twoqueList" in the request. And it looks like each entry in that list is simply a list of, um, let's just say somethings. I would change that so that each entry is a bean which contains two things: the colour of the row and the list of somethings.
 
Steve Dyke
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:
Well, if it were me, I would do some more work in the part of your code (presumably it's a servlet) which puts information into the request context. Have it put the colour in a place where it's immediately accessible when you generate the TR tag.

Looks to me like you have put a list "twoqueList" in the request. And it looks like each entry in that list is simply a list of, um, let's just say somethings. I would change that so that each entry is a bean which contains two things: the colour of the row and the list of somethings.



This is my servlet code that generates my list of lists. The last element added has the color flag. What would I do here to fix it so the JSP could see the color flag at the time the row is defined(the first forEach loop):

 
reply
    Bookmark Topic Watch Topic
  • New Topic