I have an several image in database saved as String and i want to loop in them and view them dynamically using primefaces. the output is: sometimes show one image or two or nothing And I used all scopes (session ,view ,request) the result is the same.
here is the code, i used to convert string to streamed Content :
private StreamedContent getImageFromString(String imageData) throws IOException {
byte[] imageByte = null;
BufferedImage imageBuffer = null;
imageByte = byteToString(imageData);
ByteArrayInputStream in = new ByteArrayInputStream(imageByte);
imageBuffer = ImageIO.read(in);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(imageBuffer, "png", os);
return new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png");
}
public byte[] byteToString(String imageStr) {
return Base64.decodeBase64(imageStr);
}
and the jsf design is :
<ui:repeat value="#{recent.recentlist}" var="recent" >
<h:outputText value="#{recent.Id}"/>
<br/>
<p:graphicImage value="#{recent.graphicImage}">
<f:param name="image_id" value="#{recent.Id}"/>
</p:graphicImage>
<br/><br/>
<p:separator/>
</ui:repeat>
the result all the time is ( SEVERE: Error in streaming dynamic resource )