• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Changing styles in Struts  RSS feed

 
author
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone!

I am trying to reproduce a fragment of a Tapestry page using Struts, to understand the differences between the frameworks. I know Tapestry pretty well, but only the basics of Struts. Maybe because of this my results are quite ugly. There are actually two problems, but I will start from just one.

I want to display a table iterating through records of a List taken from request, quite a basic stuff. I am doing it like this:



The problem is that I want to show the rows in alternating styles, say, class="odd" for odd rows and class="even" for the even ones. The only solution I can see is to do like this:

<tr
[some ugly and huge conditional tag (or tags) evaluating some variable (not clear how to set and use it without scripting) and choosing a style appropriately]
>

Is there any elegant solution for this?

All right, and the second problem. I want some rows in this table to be shown bold if the link wasn't yet visited (this is defined by the 'viewed' property). Right now, I don't see anything better than doing it like this:



I have found in the Internet that "Jakarta Struts Cookbook" by Bill Siggelkow contains a section "4.3 Alternating Table Row Colors" - perhaps, the solution for the first problem can be found there. Maybe someone has this book and can give me a hint what to do?

Thanks!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're just starting to learn Struts, my recommendation would be to spend your time learning only the html:xxx tags and use JSTL for most everything else. JSTL is more standard and more powerful, and I would expect that eventually the logic:xxxx and bean:xxx tags will be discontinued.

Here is a link describing how to alternate colors in a table using the JSTL forEach tag.
 
Alexander Kolesnikov
author
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Merrill,

That's a neat solution for row styles alteration. If EL is available.

But it is not clear if anything can be done about <b> tags in the same way.

Yes, I will go and replace Struts-specific tags with JSTL.

Thanks!
 
Alexander Kolesnikov
author
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh...

Looks like I've got a problem with EL. I am running Tomcat 5.0.28 which implements JSP 2.0, I have put jstl.jar and standard.jar into WEB-INF/lib of my little Struts app, but when I am trying to use something like ${records[1].id} in JSP, it is just printed out, not evaluated.

<c:forEach var="record" items="${records}"> also doesn't work.

Did I miss something?

As far as I know, EL should be enabled by default.
 
Alexander Kolesnikov
author
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AHA!

Solved this puzzle myself. Will explain here in case someone will meet the same problem.

All my fuss with JARs was in vain: as of JSP 2.0 EL is built-in, no JARs are needed for it. BUT it is enabled by default only if web.xml is written according to 2.4 specs. The difference is that it uses Schema instead DTD. And I used web.xml which comes with Struts blank webapp. Funny enough, it is version 2.2 in the latest distribution of Struts.

I removed DOCTYPE, pasted in appropriate Schema reference, and EL started working for me.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!