I'm implementing a page where I need to display a datagrid with the values of a table in the database. Each row in the table has a blob-like image.
But when you try to display the image with the primefaces by the:: tag, it does not appear.
Below is the part of the entity code where you have the image property and the function that places it in the DefaultStreamedContent format that is supported by the primefaces tag.
@Lob
@Basic(fetch= FetchType.LAZY)
private byte[] imagem;
public Projetista() {
}
public StreamedContent mostrarImagemDeByte(){
InputStream in = null;
StreamedContent sc;
if(this.imagem != null){
in = new ByteArrayInputStream(this.imagem);
}
if( in != null){
sc = new DefaultStreamedContent(in);
}else{
sc = null;
}
return sc;
}
below the part of the code of the page where I use to display the image
<div id="envolveTexto">
<div id="texto">
<p:dataGrid columns="3" value="#{projetistaBean.listaDeProjetistas}" var="projetista" >
<p:panelGrid columns="1">
<p:graphicImage value="#{projetista.mostrarImagemDeByte()}" width="70" height="70" />
<h:outputText value="#{projetista.nome}" />
</p:panelGrid>
</p:dataGrid>
</div>
</div>
It was to appear a datagrid with the images that are in the database, together with the name of each one of them.