title: Passing a List of Objects to Freemarker and then Looping
body: <p>I've been acquainting myself with FreeMarker, a template engine for Java. </p>
  
  <p>I got to the point where I am able to pass an object to the template engine through a Hash Map. That works alright. But as soon as I try to pass any sort of set of multiple objects to FreeMarker it gives me a freemarker.template.TemplateException and complains that it "Expected collection or sequence. jobs evaluated instead to freemarker.template.SimpleHash".</p>
  
  <p>From what I understand from reading up on this in the various resources, this is to be expected.</p>
  
  <p>Now, I have done much of the leg work and found a number of people commenting on how to get around this. But, quite frankly, (a) for many of the examples it was unclear as to how exactly their advice applies in my case--even though I've known Java basics for quite a while I'm pretty new to some of the architecture pertaining to Java web apps  and (b) I'm confused as to which of the approaches was the best approach.</p>
  
  <p>All I want to do, at the most simplified  level, is basically this:</p>
  
  <ol>
  <li><p>I have a simple Servlet.</p></li>
  <li><p>I have a simple class (for this example named Invoice) with a few methods and properties.</p></li>
  <li><p>I want to have my servlet (in some fashion) present a list/array/sequence/hashmap of instances of these objects (or views of those objects) via FreeMarker's process method.</p></li>
  <li><p>I want to have my .ftl template do a loop through the list/array/sequence/hashmap and display method results, something like this:</p></li>
  </ol>
  
  <pre class="lang-html prettyprint-override"><code>&lt; # list invoices as invoice&gt; 
  Invoice note: ${invoice.getNote()}, Invoice Amount:${invoice.getAmount()} 
  &lt; / # list&gt;
  </code></pre>
  
  <p>Now, I'm not necessarily looking for the quick &amp; dirty solution to this. I'm new to FreeMarker, but I want to do this in the proper way that is elegant and good design. So I'm open to completely rethinking this approach. Can someone help me see what I need to do to get something like this to work?</p>