休止状態フレームワークを使用して、データベースから 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);
}
}
}
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>
現在は正常に動作していますが、ここでは 2 つのドキュメントのみです。特定のユーザーの複数のドキュメント タイプの場合。JSFで画像を表示するにはどうすればよいですか? 画像をレンダリングするための最良の代替手段は何ですか?