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.
To access the iterators of your Iterables in EL expressions in your JSTL tags, you could use Java code (in your model, controller or service layer) that wraps your Iterable objects in instances of a class Iter that looks like this (with a simple getter method that follows the Java beans method name convention):
public class Iter<T> {
private final Iterable<T> iterable;
public Iter(Iterable<T> iterable) {
this.iterable = iterable;
}
public Iterator<T> getIterator() {
return iterable.iterator();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With