title: primefaces graphicimage from database not loading
body: <p>I am having trouble displaying image from database on a primefaces graphicimage component. I  am using primefaces 3.4.2, jsf 2.2, glassfish 3.1.2.2. Following is the simple code I am trying. I went through other posts related to p:graphicimage and incorporated the recommendations, still I gouldnt make this work. What is wrong here?</p>
  
  <p>index.xhtml</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"&gt;
  &lt;h:head&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;h:form id="f1"&gt;
          &lt;p:panel style="height: 500px ; width: 800px" visible="true"&gt;
              &lt;p:graphicImage value="#{treeBean.image}" /&gt;
          &lt;/p:panel&gt;
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>TreeBean.java</p>
  
  <pre><code>@Named
  @ApplicationScoped
  public class TreeBean implements Serializable{
      @EJB
      private ImageEJB imageEjb;
      public StreamedContent getImage() throws IOException{
          FacesContext context = FacesContext.getCurrentInstance();
          if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
              return new DefaultStreamedContent();
          }
          else {
              Decisiontree dr = imageEjb.getTree();
              return new DefaultStreamedContent(new ByteArrayInputStream(dr.getImage()));
          }
      }
  }
  </code></pre>
  
  <p>This is what I see in the browser console.</p>
  
  <p><img src="https://i.stack.imgur.com/n1Z2R.jpg" alt="Error in console"></p>