I have an application that calls a service that returns a Json string with about ten images as byte array. I loop through the Json string and pull out the images and convert them to StreamedContent and place them into an object then populate a List with the object that has the image and name of that image. I am trying to display those image in a JSF page with the PrimeFaces tag, but the images are not displaying. My code follows:
ImageBackingBean
private String sku;
private StreamedContent image;
private List<ImageBackingBean> imageList;
public String getSku(){
return sku;
}
public void setSku(String sku){
this.sku = sku;
}
public StreamedContent getImage() {
FacesContext context = FacesContext.getCurrentInstance();
if(context.getRenderResponse()){
return new DefaultStreamedContent();
}else{
String id = context.getExternalContext().getRequestParameterMap().get("sku");
List<ImageBackingBean> list = getImageList();
for(ImageBackingBean bean : list){
if(bean.getSku().equalsIgnoreCase(id)){
return bean.getImage();
}
}
}
return image;
}
public void setImage(StreamedContent image) {
this.image = image;
}
public List<ImageBackingBean> getImageList(){
return imageList;
}
public void setImageList(List<ImageBackingBean> imageList){
this.imageList = imageList;
}
public String getImageFromDatabase() throws IOException{
setImageList(DBImages.getImages());
if(getImageList() == null){
return "error";
}
return "success";
}
My JSF page is simple and is as follows:
<h:dataTable var="items" value="#{imageBackingBean.imageList}">
<h:column>
<p:graphicImage value="#{items.image}">
<f:param name="sku" value="#{items.sku}" />
</p:graphicImage>
</h:column>
</h:dataTable>
Everything I've read online tells me this is how I need to display dynamic images. Should I not store the images as type StreamedContent in the list?