データグリッド列に画像を表示する際に問題があります。Datagrid が読み込まれると画像が正しく表示されますが、2 ページ目をクリックするか最初のページを更新すると、画像が消えます。コンソールで、2 番目のページをクリックするか、ページを更新すると、パラメータ値が null になっていることに気付きました。そのため、画像は表示されません。セッションスコープを使用しています。以下は私のコードです:
public StreamedContent getStreamedImageById() {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getRenderResponse()) {
// So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
System.out.println("check");
return new DefaultStreamedContent();
}
else {
// So, browser is requesting the image. Get ID value from actual request param.
String firstName = context.getExternalContext().getRequestParameterMap().get("firstName");
System.out.println("Name:"+firstName);
System.out.println("Image::"+images.get(firstName));
return images.get(firstName);
}
検索方法では、ハッシュ マップ内のすべての画像を取得します。
while(itr.hasNext()){
com.sysvana.request.UserBean us=itr.next();
images.put(us.getFirstName(), stringToStreamedContent(us.getJpegPhoto()));
}
これが私のxhtmlです::
<p:graphicImage value="#{userManagementActionBean.streamedImageById}" height="40" width="50" style="align:center" >
<f:param id="firstName" name="firstName" value="#{user.firstName}" />
</p:graphicImage>