Struts logic:iterate questions

Posted on 2006-03-27
Last Modified: 2010-04-01
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 !!
Question by:clo1
    LVL 6

    Accepted Solution

    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>

    LVL 3

    Assisted Solution


    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    After several days of searching and hunting for limited documentation, I wanted to share this guide to hopefully save someone the hassle of trying to figure this out on their own. I have tested this on Xendesktop 7.1 and PS 4.5 running simultaneous…
    This post first appeared at Oracleinaction  ( Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now