File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Changing styles in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Changing styles in Struts" Watch "Changing styles in Struts" New topic
Author

Changing styles in Struts

Alexander Kolesnikov
author
Ranch Hand

Joined: Feb 26, 2005
Posts: 99
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!


Alexander Kolesnikov<br />Java Web Developer<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3<br /><a href="http://sundraw.ws" target="_blank" rel="nofollow">Tapestry 5: Building Web Applications</a><br /><a href="http://sundraw.ws/batik.jsp" target="_blank" rel="nofollow">Java Drawing With Apache Batik</a>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Alexander Kolesnikov
author
Ranch Hand

Joined: Feb 26, 2005
Posts: 99
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
Ranch Hand

Joined: Feb 26, 2005
Posts: 99
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
Ranch Hand

Joined: Feb 26, 2005
Posts: 99
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing styles in Struts