title: How to use p:graphicImage with StreamedContent within p:dataTable?
body: <p>I want to dynamically load images from a database withing a PrimeFaces data table. Code looks like as follows which is based on <a href="http://forum.primefaces.org/viewtopic.php?f=3&amp;t=4163&amp;hilit=p%3AgraphicImage" rel="noreferrer">this PF forum topic</a>:</p>
  
  <pre><code>&lt;p:dataTable id="tablaInventario" var="inv" value="#{registrarPedidoController.inventarioList}" paginator="true" rows="10"
      selection="#{registrarPedidoController.inventarioSelected}" selectionMode="single"                                     
      update="tablaInventario tablaDetalle total totalDesc" dblClickSelect="false" paginatorPosition="bottom"&gt;
      &lt;p:column sortBy="producto.codigo" filterBy="producto.codigo"&gt;
          &lt;f:facet name="header"&gt;#{msg.codigo}&lt;/f:facet&gt;
          #{inv.producto.codProducto}
      &lt;/p:column&gt;                            
      &lt;p:column&gt;
          &lt;f:facet name="header"&gt;Foto&lt;/f:facet&gt;
          &lt;p:graphicImage id="photo" value="#{registrarPedidoController.streamedImageById}" cache="FALSE"&gt;
              &lt;f:param name="inv" value="#{inv.id}" /&gt;
          &lt;/p:graphicImage&gt;                                
      &lt;/p:column&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>with</p>
  
  <pre><code>public StreamedContent getStreamedImageById() {
      DefaultStreamedContent image = null;
      String get = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("inv");
      System.out.println("[Param]: " + get); // This prints null.
      Long id = new Long(get);
      List&lt;Inventario&gt; listInventarios = controladorRegistrarPedido.listInventarios();
  
      for (Inventario i : listInventarios) {
          if (i.getId().compareTo(id) == 0) {
              byte[] foto = i.getProducto().getFoto();
              image = new DefaultStreamedContent(new ByteArrayInputStream(foto), "image/png");
          }
      }
  
      return image;
  }
  </code></pre>
  
  <p>However I can't get it work. My param is passing "null" to my backing bean. How is this caused and how can I solve it?</p>
  
  <p>I am using Netbeans 6.9.1, JSF 2.0 and Primefaces 2.2.RC2.</p>
  
  <p>I went on using BalusC first solution, it worked fine but images aren't being rendered in the UI. Exceptions Glassfish is throwing up:</p>
  
  <pre><code>WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
  java.lang.NullPointerException
          at com.sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.isInScope(BeanManager.java:552)
  </code></pre>
  
  <p>Well seems I get working thanks to BalusC. I've to used RequestScoped, SessionScoped or ApplicationScoped for managing the getStreamedImageId. However in the UI is always setting the default image (for the null cases) and not as expected the image that correspondes to each row. The new code is:</p>
  
  <pre><code>public StreamedContent streamedById(Long id) {
      DefaultStreamedContent image = null;
  
      System.out.println("[ID inventario]: " + id);
  
      List&lt;Inventario&gt; listInventarios = controladorRegistrarPedido.listInventarios();
      for (Inventario i : listInventarios) {
          if (i.getId().equals(id)) {
              byte[] foto = i.getProducto().getFoto();
              if (foto != null) {
                  System.out.println("   [Foto]: " + foto);
                  image = new DefaultStreamedContent(new ByteArrayInputStream(foto), "image/png");
                  break;
              }
          }
  
  
      }
      if (image == null) {
          System.out.println("       [Image null]");
          byte[] foto = listInventarios.get(0).getProducto().getFoto();
          image = new DefaultStreamedContent(new ByteArrayInputStream(foto), "image/png");
      }
  
      System.out.println("   [Foto Streamed]: " + image);
  
      return image;
  
  }
  </code></pre>