I have successfully implemented the solution suggested by BalusC for rendering dynamic images inside a datatable (code posted further down here). Problem I am facing is this:
Issue
I am using pagination in datatable and when I move to the page which I have never visited, the images render fine. But when I come back to the page I had visited earlier, the images don't show up even though the StreamedContent is returned for that image.
Code
// ImageBean - SessionScoped
// Get image for compound
public StreamedContent scaledImageById() {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
return new DefaultStreamedContent();
} else {
String idStr = context.getExternalContext().
getRequestParameterMap().get("id");
StreamedContent image = scaledCompoundImageMap.
get(Integer.valueOf(idStr));
return image;
}
}
// Controller - ViewScoped
<p:dataTable id="cTable" value="#{controller.compoundList}" var="compound">
<p:column headerText="Structure" style="text-align:center">
<p:graphicImage id="scaledImage"
value="#{imageBean.scaledImageById()}"
cache="false">
<f:param name="id" value="#{compound.id}" />
</p:graphicImage>
</p:column>
...
So when I visit a new page in the paginator, the images display fine. But when I come back to an already visited page, the images are not shown (even though the scaledImageById is called twice and the StreamedContent is returned fine).
Please let me know if you need any other code here and any help would be much appreciated. Thanks.
Abdul