I trying to display the multiple images in xhtml page from database using hibernate framework. But the images was not displayed. I mentioned code snippet below
public class ImageRenderBean{
private String imageName;
private StreamedContent image;
//setters and getters
}
RPCDocumentBean Managed Bean:
public class RPCDocumentBean implements Serializable {
private List<ImageRenderBean> docRendList;
public RPCDocumentBean(){
List<RPCDocument> list=getRpcService().find();
ImageRenderBean renderBean=null;
for(RPCDocument doc:list){
renderBean=new ImageRenderBean();
renderBean.setImageName(doc.getDocumentName());
renderBean.setImage( new DefaultStreamedContent(new ByteArrayInputStream(
doc.getRpcProofdoc()), "png"););
docRendList.add(renderBean);
}
}
}
document.xhtml :
<ui:repeat var="docRenPath" value="#{rpcdocumentBean.docRendList}>
<p:graphicImage id="img1" width="100px" height="100px" value="#{docRenPath.imageRender.image}" style="cursor:pointer"/>
</ui:repeat>
But images was not displayed.So I changed core logic at Managed Bean like
public class RPCDocumentBean implements Serializable {
private List<String> docRendList;
private StreamedContent rpcdocument1;
private StreamedContent rpcdocument2;
public RPCDocumentBean(){
List<RPCDocument> list=getRpcService().find();
ImageRenderBean renderBean=null;
for(RPCDocument doc:list){
renderBean.add(doc.getDocumentName());
if(doc.getDocumentName().equals("identityproof")){
rpcdocument1=new DefaultStreamedContent(new ByteArrayInputStream(
doc.getRpcProofdoc()), "png"));
}
if(doc.getDocumentName().equals("addressproof")){
rpcdocument2=new DefaultStreamedContent(new ByteArrayInputStream(
doc.getRpcProofdoc()), "png"));
}
}
}
}
After modification at xhtml page:
<ui:repeat var="docRenPath" value="#{rpcdocumentBean.docRendList}>
<p:row rendered="#{docRenPath.equalsIgnoreCase('identityproof')}" >
<p:column >
<p:graphicImage id="img1" width="100px" height="100px" value="#{rpcdocumentBean.rpcdocument1}" style="cursor:pointer"/>
</p:column>
</p:row>
<p:row rendered="#{docRenPath.equalsIgnoreCase('addressproof')}" >
<p:column >
<p:graphicImage id="img1" width="100px" height="100px" value="#{rpcdocumentBean.rpcdocument2}" style="cursor:pointer"/>
</p:column>
</p:row>eat>
Now its working fine.But here two document only. If more than documents type for particular user. How can i display images in JSF? What is best alternative to render images?