title: JSTL forEach to iterate over user defined class implementing Iterable
body: <p>my ask is similar to the one asked here:
  <a href="https://stackoverflow.com/questions/2978536/jstl-using-foreach-to-iterate-over-a-user-defined-class">JSTL - Using forEach to iterate over a user-defined class</a>
  However, the (obvious and simple) solution does not work for me, so I am asking again looking for any advice.</p>
  
  <p>I have a simple class implementing Iterable interface, like:</p>
  
  <pre><code>public class Lizt implements Iterable&lt;String&gt; {
  
    private ArrayList&lt;String&gt; inner = new ArrayList&lt;&gt;();
  
    public Lizt(){
      this.inner.add("A");
      this.inner.add("B");
    }
  
    @Override
    public Iterator&lt;String&gt; iterator() {
      return inner.iterator();
    }
  
    public Iterable&lt;String&gt; getInner(){
      return this.inner;
    }
  }
  </code></pre>
  
  <p>(Ignore "getInner()" function for now).
  Then I have a simple JSP page:</p>
  
  <pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
  &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;jsp:useBean id="lst" scope="session" class="model.Lizt"/&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;ul&gt;
  &lt;c:forEach var="item" items="${lst}"&gt;
      &lt;li&gt;${item}&lt;/li&gt;
  &lt;/c:forEach&gt;
  &lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>So, I am trying to iterate over an instance implementing Iterable. However, the server returns me (among the others)  </p>
  
  <pre><code>javax.servlet.ServletException: org.apache.jasper.JasperException: An exception occurred processing JSP page [/forEachTest.jsp] at line [7]
  ...
  Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in &amp;lt;forEach&amp;gt;
  </code></pre>
  
  <p>If I replace the JSP expression to access directly the internal inner field, like</p>
  
  <pre><code>&lt;c:forEach var="item" items="${lst.inner}"&gt;
  </code></pre>
  
  <p>... everything works fine. Where is the difference between "my" Iterable and ArrayList's Iterable?</p>
  
  <p>Thanks for any advice in advance.</p>