• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

varStatus in c:forEach

 
Rahul Jadaun
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of 'varStatus' in <c:forEach>

getCount() starts from 1 while getIndex() starts from 0.
Please confirm.
 
Ashwini Hegde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

    ------------------------------------------------------------------------
     
    Rahul Jadaun
    Ranch Hand
    Posts: 36
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ashwini..!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic