title: Displaying dynamic images inside PrimeFaces list box
body: <p>Playing with PrimeFaces, I successfully produced dynamically generated image and displayed it in p:graphicImage, but a selectOneListbox is not displaying the images, generated by the same code.</p>
  
  <p>JSF:</p>
  
  <pre><code>&lt;p:selectOneListbox id="imgListBox" value="#{Bean.selectedimg}" var="img" style="height:600px; width: 400px"&gt;
      &lt;f:selectItems value="#{Bean.availableimgs}" var="img" itemLabel="#{img.imgName}" itemValue="#{img}" /&gt;
  
      &lt;p:column&gt;
          &lt;p:graphicImage value="#{img.picture}" alt="#{img.imgFileName}"/&gt;
      &lt;/p:column&gt;
  
      &lt;p:column&gt;
          &lt;p:outputLabel id="imgNameLabel" value="#{img.imgName}"/&gt;
      &lt;/p:column&gt;
  &lt;/p:selectOneListbox&gt;
  </code></pre>
  
  <p>Bean:</p>
  
  <pre><code>private StreamedContent Picture;
  
  public StreamedContent getPicture() throws IOException {
      if (Picture == null) {
          ...
          ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
          ImageIO.write(im, "png", byteStream);
          // ImageIO.write(im, "png", new File(String.format("/home/user/Desktop/IMG/%s.png", imgFile.getName())));
          this.Picture = new DefaultStreamedContent(new ByteArrayInputStream(byteStream.toByteArray()), "image/png");
          return this.Picture;
      }
  }
  </code></pre>
  
  <p>All that's there is alt text. Dumping images into a file in a commented out line works fine. Dumping returned StreamedContent object into a label works fine too and displays its string representation:</p>
  
  <pre><code>org.primefaces.model.DefaultStreamedContent@47afcfac
  org.primefaces.model.DefaultStreamedContent@1b43fbba
  </code></pre>
  
  <p>and so on. Image src tags also seem to be populated similarly to the working single image above:</p>
  
  <pre><code>/testJSF/faces/javax.faces.resource/dynamiccontent.properties?ln=primefaces&amp;amp;pfdrid=pfdrid_d905ac48-0fb4-4d2c-8282-9c84a714a92c
  </code></pre>
  
  <p>but no images in any of the browsers I've access to (Epiphany, IE9 32/64bit, FF13 Linux, FF21 Win7)</p>
  
  <p>Trying such and such to get list to work, I noticed that NetBeans always 'Fixed imports' for @SessionScoped bean annotation by adding import <strong>javax.enterprise.context.SessionScoped</strong> and the page worked (except graphics). The beans in PrimeFaces demo examples are injected by way of faces-config.xml as request scoped. If I used @RequestScoped annotation with <strong>import javax.faces.bean.RequestScoped;</strong> then nothing related to the bean would work. Also if I changed import for @SessionScoped annotation to <strong>javax.faces.bean.SessionScoped</strong> then nothing would work too. Can anyone explain what annotations should be used on the beans backing PrimeFaces JSF and with what imports, as this is too confusing for a noob like me?</p>
  
  <p>Worst part is that simple graphicsImage works only once with @SessionScoped bean importing <strong>javax.enterprise.context.SessionScoped</strong>. If I refreshed the page, than images would be gone (actual URLs would change and nothing would be at the old URLs) until clean/build is repeated, and the method calls would not be re-entered in debugger during the refresh.</p>
  
  <p>I am obviously doing something wrong.</p>