我尝试使用休眠框架从数据库中显示 xhtml 页面中的多个图像。但是图像没有显示。我在下面提到了代码片段
public class ImageRenderBean{
private String imageName;
private StreamedContent image;
//setters and getters
}
RPCDocumentBean 托管 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);
}
}
}
文档.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 中显示图像?渲染图像的最佳选择是什么?