• 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

Changing line alternate line color using tags

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone have an example of how you would use custom tags to change the line color in a table of results, so that its a bit clearer where one line ends and another begins.
I don't know if i've made myself very clear. For example, if i had a table with 10 lines of information i want the 1st line in yellow (say) then the second in green, then the next in yellow, then green, and so on.
Any help would be much appreciated. Been searching the net for ages without any success.
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Does anyone have an example of how you would use custom tags to change the line color in a table of results, so that its a bit clearer where one line ends and another begins.
I don't know if i've made myself very clear. For example, if i had a table with 10 lines of information i want the 1st line in yellow (say) then the second in green, then the next in yellow, then green, and so on.


You already know how to make custom tags that use doAfterBody, call getBodyContent and read/modify their body content, right (if not, see Ch. 14 of http://pdf.coreservlets.com)? If so, you could certain wrap such a tag around a table so that it searches for the TR tag and adds a BGCOLOR attribute.
Sounds like more trouble than it is worth, though. Why not just use a style sheet:

Cheers-
- Marty
 
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would rather use a simple approach of using a boolean

This sure is elementary but what's the harm?
[ February 13, 2003: Message edited by: Debashish Chakrabarty ]
 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I guess they both seem like good suggestions, but neither is suitable. I can't use style sheets because there is only one row (which is iterated over repeatedly) which means there is effectively no even row to give a style to. Also, the code has to be in a custom tag. The rest of the site is written entirely in custom tags and struts.
 
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
Regardless of where the rows are generated (on-page, or in tag code) there's probably a loop that is generating the multiple rows in which you can keep track of odd/even rows. How does this prevent you from applying alternate styles to the rows?
hth,
bear
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tony Walters:
Well, I guess they both seem like good suggestions, but neither is suitable. I can't use style sheets because there is only one row (which is iterated over repeatedly) which means there is effectively no even row to give a style to. Also, the code has to be in a custom tag. The rest of the site is written entirely in custom tags and struts.


Why didn't you say so? In that case, check here:
http://husted.com/struts/resources/rowtag.zip
This is a good, working set of tags. I used it myself until I wrote my own set of tags in our own packaging for other reasons.
For other resources, check the struts resources page at http://jakarta.apache.org/struts/userGuide/resources.html
(And I suggest posting struts questions in the framework forum! )
 
Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestions everyone. Unfortunately, while they all would work, the spec i am working to dictated that none of them are suitable for this particular application. The tag needs to operate without generating html - so, having had a quick look, Davids tags don't suit as they generate the 'td' tags.
Maybe it can't be done. I thought i had seen an example somewhere but didn't bookmark it.
I'll give the struts forum a go if i get time. I thought posting here was more suitable because custom tags are not strictly to do with struts but JSP.
Thanks again for the suggestions.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The tag needs to operate without generating html
I may be misinterpreting you here, but HTML is what web pages are made of, and even CSS depends on HTML markup to tell it what to act on. If you want to change how specific parts of a web page look, you have to use different HTML.
If what you really mean is that the <TD> etc. are already generated, then you can do this several ways, but really it's much more of a HTML/JavaScript/CSS issue than one of JSP tags.
My suggestion is to take an example of the existing output, save it to a file, and experiment by editing it manually to see if you can achieve what you want without changing the already fixed bits. When you find somethning you like, you can put the changes you prefer into a tag.
Possible ways of doing it:
  • generate a nested table inside each table cell, with width 100%, no padding or spacing, and a single cell of the appropriate background color
  • wrap your cell contents in something recognizable by CSS (alternation stylesof "span" or whatever) and apply CSS changes to set the color
  • mark your lines some other (non-HTML?) way and install a filter catching the output of the JSP which patches the <TD> when it sees your marker.


  • Others are probably possible. Ask in HTML/JavaScript and I expect you'll get some suggestions!
     
    David Hibbs
    Ranch Hand
    Posts: 374
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Tony Walters:
    The tag needs to operate without generating html - so, having had a quick look, Davids tags don't suit as they generate the 'td' tags.
    Maybe it can't be done. I thought i had seen an example somewhere but didn't bookmark it.


    If you saw it, it almost had to be at a site devoted to dhtml and/or javascript. Try http://DynamicDrive.com and http://javascript.internet.com/
    IMHO though it's a bogus requirement for a tag to not generate HTML tags.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic