0

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?

Jean Marcos
  • 167
  • 6
tech2504
  • 847
  • 4
  • 19
  • 33
  • 1
    possible duplicate of [How to use with DefaultStreamedContent in an ui:repeat?](http://stackoverflow.com/questions/10944673/how-to-use-pgraphicimage-with-defaultstreamedcontent-in-an-uirepeat) and [Display image from database with p:graphicImage](http://stackoverflow.com/questions/8207325/display-image-from-database-with-pgraphicimage/) – BalusC Apr 23 '13 at 18:20
  • 3
    Huh? So you didn't understood anything from those answers? I suggest to take a break, breathe deeply a few times and re-read them again and recreate/experiment the proposed solution in your project. – BalusC Apr 23 '13 at 18:32

0 Answers0