• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 802
  • Last Modified:

Struts logic:iterate questions

I am using logic:iterate like follow

      java.util.ArrayList keyList = new java.util.ArrayList();
      pageContext.setAttribute("keyList", keyList, PageContext.PAGE_SCOPE);

    <logic:iterate id="keyListing" name="keyList">
          <bean:write name="keyListing" />

I would like to know

1. How can I display a link for each row after the displaying of "key1", "key2", "key3" ?
2. How can I check if it is the last element in the collection, i.e. key3 ?

Please help. Thanks a lot !!
2 Solutions
Answer to your first question

Add a line after the below statement in your code

> <bean:write name="keyListing" />
<a href="your link">your text</a>


use bean:size to get the size of your list, or hardcode it to 3 ;) store it in a id.
like:                 <bean:size id="total"  name="keyList"/>

<logic:iterate id="keyListing" indexId="index" name="keyList">

now you can check if (total-1=index) to get your last element.


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now