Web tier: servlets, JSP, Web frameworks: struts - <logic:iterate> indexId question
- Posted by: Gary Gu
- Posted on: April 06 2004 16:06 EDT
In Struts using <logic:iterate> - one of its attributes is "indexId". Question is how I can decide the this indexId is odd or even number.
- <logic:iterate> indexId by Wade Robbins on April 06 2004 17:21 EDT
- <logic:iterate> indexId by Wade Robbins on April 07 2004 10:09 EDT
you could simply do
Not a great solution but it works
I would not like to use scriptlet. So this solution does not work for me. Thanks.
If you are on a Servlet 2.3/JSP 1.2 compliant application server, use JSTL with its expression language support for this kind of logic. The JSTL c:forEach tag does everything the Struts logic:iterate tag does, and much more. The logic tags in Struts are pretty weak, and are unlikely to improve since Struts is 100% compatible with JSTL.
If you are on an older server, scripting is probably your easiest solution, short of writing your own custom tags.
JSTL has %(mod) operator. I am supprised Struts tag lib does not have one similar, or I missed it. However, I am working on WebSphere 5.x, and Struts tab lib and JSTL tag lib it included have conflict each other. Maybe the versions of both lib bundled with WebSphere are not compatible and I really need to download newest versions of both? Anyone has ideas?
I suggest you update Struts and JSTL if you can, to resolve the conflict.
If you can't, there are other tag libraries that can do the same thing, like the on the previous poster suggest, or the WebOGNL tag library:
Just a simple question.
Why do you need to do that in the first place? If you are doing alternate colors for a table I would suggest you look into displaytag component.
It's a really good tag library and works great with struts.