struts - <logic:iterate> indexId question


Web tier: servlets, JSP, Web frameworks: struts - <logic:iterate> indexId question

  1. struts - <logic:iterate> indexId question (6 messages)

    Hi All,

    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.



    Threaded Messages (6)

  2. <logic:iterate> indexId[ Go to top ]

    you could simply do
      boolean odd=true;
      if (indexId%2==0){

    Not a great solution but it works
  3. <logic:iterate> indexId[ Go to top ]

    I would not like to use scriptlet. So this solution does not work for me. Thanks.
  4. <logic:iterate> indexId[ Go to top ]

    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.
  5. <logic:iterate> indexId[ Go to top ]

    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?

  6. <logic:iterate> indexId[ Go to top ]

    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:
  7. <logic:iterate> indexId[ Go to top ]

    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.