File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

'break' functionality in a forEach tag ?

 
John Stein
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Does anyone know of a way to 'break' out of a JSTL forEach tag - without using scripting ? I'm using the 'items' format of the tag as opposed to the 'begin / end' format and would like to break out of the loop (based on the value of an EL variable) to save having to loop needlessly around a, potentially large, structure.

I've had a dig around and can't find any official solution to this problem. Can anyone think of a decent workaround ?

Thanks in advance,

John.
[ February 20, 2006: Message edited by: John Stein ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is no break mechanism.

You could put an if condition inside the loop that skips over the body once you detect your "break" value, but the best work-around would be to re-structure the collection such that no breaking is necessary in the first place.

When creating scriptless pages in JSP, it's important to make a slight shift in attitude and approach: make the data cater to the page, rather than the other way around.
 
John Stein
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the-condition-inside-the-loop that you mentioned was really the only workaround I could come up with. Only thing is that it still enters the loop for the maximum number of times. But, I think its probably the approach I'll need to take.

In the design stage, I did originally consider 'tailoring' the data to suit the page, but this approach would have meant the controller handling stuff that is completely view-centric. I think you're right tho, the scriptless JSP approach does require a slight shift in attitude and a slight move away from the perceived wisdom.

Thanks for your response.

John.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic