title: jsf primefaces how to display graphicimage in datatgrid from folder and use it everywhere?
body: <p>I'm trying to display images from a folder outside from my webapp folder with p:graphicImage inside a p:dataGrid but it does'nt work. However I wish to use URL's images for displaying them in another website.
  Here what I tried :</p>
  
  <pre><code>        &lt;!--works--&gt;
          &lt;p:graphicImage value="#{imageStreamer.getStreamedImage(fileManagerBean.resources.get(0))}" width="100"/&gt;
          &lt;!--does'nt work--&gt;
          &lt;p:dataGrid id="dataGrid" var="file" value="#{fileManagerBean.resources}" &gt;
              &lt;p:commandLink action="#{fileManagerBean.setFicher(file)}" onclick="dialog.show();" update=":img,:url"&gt;
                  &lt;p:graphicImage value="#{imageStreamer.getStreamedImage(file)}" width="100"/&gt;&lt;br/&gt;
                  &lt;h:outputText value="#{file.name}" /&gt;
              &lt;/p:commandLink&gt;
          &lt;/p:dataGrid&gt;
  </code></pre>
  
  <p>List of files :</p>
  
  <pre><code>public List&lt;File&gt; getResources() {
          String path = "/opt/www/images";
          File resourceDirectory = new File(path);
          String[] extensions = {"png", "jpg", "jpeg", "gif"};
          Collection&lt;File&gt; files = FileUtils.listFiles(resourceDirectory, extensions, true);
  //        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  //        Set&lt;String&gt; resources = context.getResourcePaths("/images");
          List&lt;File&gt; resources = new ArrayList&lt;File&gt;();
          for (File resource : files) {
              resources.add(resource);
          }
          return resources;
      }
  </code></pre>
  
  <p>The image streamer : </p>
  
  <pre><code>@ManagedBean
  @ApplicationScoped
  public class ImageStreamer {
  
      public StreamedContent getStreamedImage(File file) {
          InputStream stream = null;
          String mimeType = null;
          try {
              stream = new FileInputStream(file);
              mimeType = URLConnection.guessContentTypeFromStream(stream);
          } catch (FileNotFoundException ex) {
              Logger.getLogger(ImageStreamer.class.getName()).log(Level.SEVERE, null, ex);
          } catch (IOException ex) {
              Logger.getLogger(ImageStreamer.class.getName()).log(Level.SEVERE, null, ex);
          }
          return new DefaultStreamedContent(stream, mimeType, file.getName());
      }
  }
  </code></pre>