Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <p:column headerText="Foto" style="text-align: center; width: 100px">
  2. <p:graphicImage value="#{pesquisaNoticiasBean.foto}"
  3. cache="disable">
  4. <f:param name="nomeFoto" value="#{noticia.foto_noticia}" />
  5. </p:graphicImage>
  6. </p:column>
  7.  
  8. public StreamedContent getFoto() throws IOException {
  9. String caminho = "C:/workspace Web/Projetos Profissionais/Fotos para teste/";//Aqui você coloca o caminho do diretório onde as imagens estão sendo armazenadas no servidor
  10.  
  11. FacesContext context = FacesContext.getCurrentInstance();
  12. String nomeFoto = context.getExternalContext().getRequestParameterMap().get("nomeFoto");
  13.  
  14. File foto = new File(caminho+nomeFoto);
  15.  
  16. DefaultStreamedContent content = null;
  17. try {
  18. BufferedInputStream in = new BufferedInputStream(new FileInputStream(foto));
  19. byte[] bytes = new byte[in.available()];
  20. in.read(bytes);
  21. in.close();
  22. content = new DefaultStreamedContent(new ByteArrayInputStream(bytes), "image/jpeg");
  23. } catch (Exception e) {
  24. e.getStackTrace();
  25. }
  26. return content;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement