title: Dynamic images with StreamedContent
body: <p>I have implemented two StreamedContent beans to dynamic load a graphic image, following the solution found 
  <a href="https://stackoverflow.com/questions/8207325/display-dynamic-image-from-database-with-pgraphicimage-and-streamedcontent">here</a></p>
  
  <p>1) With the first one I display images in a contentFlow (EVERYTHING OK)</p>
  
  <pre><code>&lt;p:contentFlow value="#{imageBean.images}" var="image"&gt;
             &lt;p:graphicImage value="#{imageStreamer.fileContent}" styleClass="content" cache="false"&gt;
                    &lt;f:param name="index" value="#{image.index}"/&gt;
              &lt;/p:graphicImage&gt;
  &lt;/p:contentFlow&gt;
  </code></pre>
  
  <p>2) With the second one I try to display images using a foreach (or repeat):</p>
  
  <pre><code> &lt;c:forEach items="#{imageBean.images}" var="item" varStatus="varStatus"&gt;
            &lt;p:graphicImage value="#{imageStreamer.fileContent}" cache="false"&gt;
                              &lt;f:param name="index" value="#{varStatus.index}" /&gt;
            &lt;/p:graphicImage&gt;
  &lt;/c:forEach&gt;
  </code></pre>
  
  <p>This doesn't work. The check (<code>context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE</code>) is always true.</p>
  
  <p>If I change the scope of the Bean to <code>RequestScoped</code> than it works! I'm confused... can someone help me?</p>
  
  <p>Managed bean:</p>
  
  <pre><code>@ManagedBean
  @ApplicationScoped
  public class ImageStreamer{
  
        public ImageStreamer(){}
  
        public StreamedContent getFileContent(){
          List&lt;Link&gt; links = this.getLinkItems();
          ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
  
          FacesContext fc = FacesContext.getCurrentInstance();
          String linkIndex = externalContext.getRequestParameterMap().get("index");
  
          if(fc.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE){
            return new DefaultStreamedContent();
          }else{
  
            int parsedIndex = Integer.parseInt(linkIndex);
            Link ql = links.get(parsedIndex);
            return new DefaultStreamedContent(new ByteArrayInputStream(ql.getBytes()), "image/png");
          }
        }
      }
  </code></pre>