title: <p:graphicImage> not rendering image
body: <p>I have a JSF page where I want to show a image. The image is stored in the database as a blob.
  The entity looks like this:</p>
  
  <pre><code>@Entity
  public class Player
  {
      @Id
      @GeneratedValue(strategy = GenerationType.TABLE)
      private Long            id;
      @Lob
      private byte[]          pictureData;
      @Transient
      private StreamedContent streamedPicture;
  
      public StreamedContent getStreamedPicture()
      {
          if (streamedPicture == null &amp;&amp; pictureData != null)
          {
              try
              {
                  ByteArrayOutputStream os = new ByteArrayOutputStream();
                  os.write(pictureData);
                  streamedPicture = new DefaultStreamedContent(
                                                      new ByteArrayInputStream(
                                                                                  os.toByteArray()),
                                                      "image/png");
              }
              catch (FileNotFoundException e)
              {}
              catch (IOException e)
              {}
          }
          return streamedPicture;
      }
  }
  </code></pre>
  
  <p>The JSF page is this:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"&gt;
  
  &lt;h:head&gt;&lt;/h:head&gt;
  &lt;body&gt;
      &lt;ui:repeat var="player" value="#{playerbean.cachedPlayers}"&gt;
          &lt;h:outputText value="#{player.id}" /&gt;
          &lt;p:graphicImage value="#{player.streamedPicture}" rendered="#{player.streamedPicture != null}"/&gt;
      &lt;/ui:repeat&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And the bean I call looks like this:</p>
  
  <pre><code>@ManagedBean(name = "playerbean")
  @SessionScoped
  public class PlayerBean
          implements Serializable
  {
      @EJB
      private PlayerManager   playerManager;
      private List&lt;Player&gt;    cachedPlayers;
  
      public List&lt;Player&gt; getCachedPlayers()
      {
          if (cachedPlayers == null)
          {
              cachedPlayers = playerManager.getAll();
          }
          return cachedPlayers;
      }
  }
  </code></pre>
  
  <p>While debugging I set a breakpoint in <code>PrimeResourceHandler</code> in the method <code>handleResourceRequest()</code>. The code of the <code>PrimeResourceHandler</code> I'm looking at contains this:</p>
  
  <pre><code>try {
      String dynamicContentEL = (String) session.get(dynamicContentId);
      ELContext eLContext = context.getELContext();
      ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), dynamicContentEL, StreamedContent.class);
      StreamedContent content = (StreamedContent) ve.getValue(eLContext);
      HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
  
      response.setContentType(content.getContentType());
  
      byte[] buffer = new byte[2048];
  
      int length;
      InputStream inputStream = content.getStream();
      while ((length = (inputStream.read(buffer))) &gt;= 0) {
          response.getOutputStream().write(buffer, 0, length);
      }
  
      response.setStatus(200);
      response.getOutputStream().flush();
      context.responseComplete();
  
  } catch(Exception e) {
      logger.log(Level.SEVERE, "Error in streaming dynamic resource.");
  } finally {
      session.remove(dynamicContentId);
  }
  </code></pre>
  
  <p>When passing the line <code>StreamedContent content = (StreamedContent) ve.getValue(eLContext);</code> <code>content</code> appears to be null. This of course causes a NullPointerException. However in the JSF page I told the element not to render if the value is null. </p>