-1

在 BalusC 博客的帮助下,我成功实现了 Primeface 数据表中的动态图像渲染。

现在我的问题是:数据进入数据表的第一页,但是如果我使用分页移动到第二页,数据就会丢失。即使我再次回到第一页,也没有任何进展。

这是我的代码:

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

}
4

1 回答 1

0

我得到了解决方案。如果有人遇到这个问题可以从中得到帮助:应该是

 if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {

        return new DefaultStreamedContent();
    }

代替

 if (context.getRenderResponse()) {

     return new DefaultStreamedContent();
  }
于 2013-11-01T11:09:25.100 回答