title: How to use <p:graphicImage> with DefaultStreamedContent in an ui:repeat?
body: <p>I was trying to display a panel where user can see a list of items category(displayed as images) and on clicking they can view products within the category(images will be displayed)</p>
  
  <p>For displaying the item category, i used the ui:repeat nad the supporting bean calss
  Below is my xhtml code</p>
  
  <pre><code>&lt;ui:repeat id="repeat" value="#{getData.images}" var="img" varStatus="loop"&gt;
  &lt;h:panelGroup&gt;
  &lt;p:graphicImage id="img1" value="#{img}" alt="image not available" &gt;
  &lt;/p:graphicImage&gt;
  &lt;/h:panelGroup&gt;
  &lt;/ui:repeat&gt;
  </code></pre>
  
  <p>And the Managed Bean Code parts</p>
  
  <pre><code>private ByteArrayOutputStream baos = new ByteArrayOutputStream();
  private List&lt;StreamedContent&gt; imageList = new ArrayList&lt;StreamedContent&gt;();
  
  public List&lt;StreamedContent&gt; getImages(){
    for (int i = 0; i &lt; sdh.getNumOfImages(); i++) {
      imageID = imageIDArray.get(i);
      ImageService imgSer = new ImageService();
      imgList.add(imageID);
      imgSer.setData(imageID);
      baos = imgSer.getImage();
      try {
        imageList.add(new DefaultStreamedContent(new 
              ByteArrayInputStream(baos.toByteArray())));
      } catch (Exception ex) {
          ex.printStackTrace();
      }
    }
    imageNum = 0;
    return imageList;
  }
  
  public StreamedContent getData() {
      baos = imageList.get(imageNum);
      //imageList.add(baos);
      imageNum++;
      return new DefaultStreamedContent(new ByteArrayInputStream(baos.toByteArray()));
  }
  </code></pre>
  
  <p>Now my problem if i don't uncomment the 'imageList.add(baos)' in 'getData', the images are not displayed.
  Now i really wants to know how the 'ui:repeat' works, since the 'imageList' contains the images and i can save the same if required in either of the method. If i specify a fixed number (ex:'imageList.get(0)') in the 'getData' method then the same image is show multiple times. Where as if i put the 'imageNum' without the 'imageList.add(baos)' it throw error 'Error in streaming dynamic resource'</p>
  
  <p>I tired Bjorn Pollex's suggestion and made the necessary changes but now images don't appear</p>