BalusC ブログの助けを借りて、Primeface データテーブルに動的画像レンダリングを実装することに成功しました。
今私の問題は次のとおりです。データはデータテーブルの最初のページに入っていますが、ページネーションデータを使用して2番目のページに移動すると失われます。最初のページに戻っても何も来ない。
ここに私のコードがあります:
<p:dataTable id="users" var="user" styleClass="userSearchTable"
paginator="true" rows="5" rowKey="#{user}"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15"
rendered="#{userManagementBean.renderSearchResultPanel}"
value="#{userManagementBean.userList}"
emptyMessage="No User Found!!"
selection="#{userManagementBean.user}" selectionMode="single">
<p:ajax event="rowSelect" update=":form,:form2"
onstart="userSelect.show()" oncomplete="userSelect.hide()"
listener="#{userManagementActionBean.viewModifyProfile()}" />
<p:column style="text-align:center">
<p:graphicImage value="#{imageUploadBean.streamedImageById}"
height="50" width="50">
<f:param id="bean" name="bean" value="#{user}" />
</p:graphicImage>
............
豆のクラス:
public StreamedContent getStreamedImageById()
throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getRenderResponse()) {
System.out.println("check");
return new DefaultStreamedContent();
}
else {
System.out.println("down");
UserBean userBean =
findByUserBean(context.getExternalContext().getRequestParameterMap().get(
"bean"));
return stringToStreamedContent(userBean.getJpegPhoto());
}
}
public StreamedContent stringToStreamedContent(String recv)
throws IOException {
try {
byte[] imageByteArray = decodeImage(recv);
InputStream is = null;
is = new ByteArrayInputStream(imageByteArray);
image =
new DefaultStreamedContent(
is, "image/jpeg");
}
catch (Exception e) {
e.printStackTrace();
}
return image;
}