0

I need to display an image using p:graphic I'm not using a p:dataTable

jsf Page

<p:graphicImage value="#{indexController.image}">
<f:param name="id" value="#{indexController.imagem.id}" />
</p:graphicImage>

my @Controller

    public StreamedContent getImage() throws IOException {
        FacesContext context = FacesContext.getCurrentInstance();

        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            return new DefaultStreamedContent();
        }
        else {
            String id = context.getExternalContext().getRequestParameterMap().get("id");
            imagem = imagemService.findById(Long.valueOf(1));
            StreamedContent sc = new DefaultStreamedContent(new ByteArrayInputStream(imagem.getArquivo()));
            return sc;
        }
    }
Kukeltje
  • 11,924
  • 4
  • 19
  • 44
  • Welcome to stackoverflow. Thank you for sharing your solution. Please tell us your reason for doing so. – Selaron Mar 14 '19 at 07:39
  • BalusC, i dont use a Data table, just help me, plz =/ – Alexsandro Andrade Mar 19 '19 at 19:56
  • To ping some user you need to prepend `@` to the name. It does not matter where the bytes come from, database or hard disk. While you did not ask a question it looks like your post is about how to display a dynamic image using StreamedContent and p:graphicImage. Therefore it is likely having a solution within the linked thread. – Selaron Mar 19 '19 at 20:42

0 Answers0