• 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();
      keyList.add("key1");
      keyList.add("key2");
      keyList.add("key3");
      pageContext.setAttribute("keyList", keyList, PageContext.PAGE_SCOPE);
%>

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

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 !!
0
clo1
Asked:
clo1
2 Solutions
 
avinthmCommented:
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>


cheers
0
 
el_diosCommented:

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.

0

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