如何将多个图像从数据库渲染到JSF?

时间:2013-04-23 18:12:27

标签: hibernate jsf primefaces

我尝试使用hibernate框架在数据库的xhtml页面中显示多个图像。但是没有显示图像。我在下面提到了代码片段

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>

但是没有显示图像。所以我改变了Managed Bean的核心逻辑,如

 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"));
    }

    }

    }


    }

在xhtml页面修改后:

   <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>

现在它的工作正常。但这里只有两个文件。如果超过特定用户的文档类型。如何在JSF中显示图像?渲染图像的最佳替代方法是什么?

0 个答案:

没有答案