Forums Register Login

varStatus in c:forEach

+Pie Number of slices to send: Send
In case of 'varStatus' in <c:forEach>

getCount() starts from 1 while getIndex() starts from 0.
Please confirm.
+Pie Number of slices to send: Send
Yes, that is correct. getIndex() is 0-based and getCount() is 1-based.

Following is an extract from the JSTL 1.1 specifications document
------------------------------------------------------------------
  • public int getIndex()Retrieves the index of the current round of the iteration. If the iteration is being performed over a subset of an underlying array, java.lang.Collection, or other type, the index returned is absolute with respect to the underlying collection.

  • Indices are 0-based.
    Returns
    The 0-based index of the current round of the iteration
  • public int getCount()

  • Retrieves the count of the current round of the iteration. The count is a relative, 1-based sequence number identifying the current round of iteration (in context with all rounds the current iteration will perform). As an example, an iteration with begin = 5, end = 15, and step = 5 produces the counts 1, 2, and 3 in that order.

    [b]Returns/[b]
    The 1-based count of the current round of the iteration

    ------------------------------------------------------------------------
    +Pie Number of slices to send: Send
    Thanks Ashwini..!
    I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 1424 times.
    Similar Threads
    varstatus in nested foreach
    Interview Questions
    save "${Value}" in a scriptlet :-/
    Struts and javascript
    Display text from MySQL Text Field
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 02:44:08.