File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Change the <c:forEach> end index at runtime in JSP. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Change the <c:forEach> end index at runtime in JSP." Watch "Change the <c:forEach> end index at runtime in JSP." New topic
Author

Change the <c:forEach> end index at runtime in JSP.

Samir Banerjee
Ranch Hand

Joined: Jun 21, 2010
Posts: 72
Hi,
My requirement is something like this :



So basically I want Index to increase at run time while the for loop is executing. In the above case although the Index increases but does not reflect in the for loop.
How can I achieve this in JSP. Any kind of help will be much appreciated. Thanks in advance.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1029
So if I understand this right, while looping through your items you can add more to your list?

Using this syntax the end index would be evaluated at the start of the loop.
It would not get re-evaluated every time through, so modifying the value $Index wouldn't change the amount of iterations.

I can't think of any way to do this with JSTL syntax directly.
One hacky workaround I can think of would be to implement an Iterator that has this functionality, and invoke the forEach tag referencing the iterator.




Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

I would back up and bit and ask why? Seems like a dicey thing to be doing and I question whether there's a better approach.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Samir Banerjee
Ranch Hand

Joined: Jun 21, 2010
Posts: 72
Sorry for the late reply! Will surely try something else to fix the case :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change the <c:forEach> end index at runtime in JSP.