We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Struts logic:iterate questions

clo1
clo1 asked
on
Medium Priority
896 Views
Last Modified: 2010-04-01
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 !!
Comment
Watch Question

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Commented:

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.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.