I’m using an API that makes heavy use of Iterables (java.lang.Iterable), but I can’t use them directly on my JSP pages because JSTL tags and EL can not process them. Right now, I’m transforming each iterable to a list prior to rendering them.
What would be the cleanest and simplest approach to make it work without previous transformations?
Do newest JSTL-Jasper-EL-taglibs-etc. versions support it? Where can I found that information? I don’t find anything about it googling…
I know I can use Iterable.iterator(), but I can’t call that method inside the JSP, only in my controller class, and this is very limiting.
You can implement your own JSP tags in Java, so you could write a tag that accepted an
Iterableand then use that in the same way as you’d use the JSTLforEachtag.This documentation has an example on how to create a custom tag that iterates through an arbitrary custom object – your implementation would likely be simpler. The key is in returning
EVAL_BODY_AGAINto allow you to process the body of the tag multiple times.http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags6.html#68297
I haven’t tried running this, but it might be something to start with: