【问题标题】:PrimeFaces Dynamic image in Datatable Pagination数据表分页中的 PrimeFaces 动态图像
【发布时间】:2013-10-31 12:57:10
【问题描述】:

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

}

【问题讨论】:

  • 你们能帮帮我吗?

标签: jsf-2 primefaces


【解决方案1】:

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

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

        return new DefaultStreamedContent();
    }

而不是

 if (context.getRenderResponse()) {

     return new DefaultStreamedContent();
  }

【讨论】:

    猜你喜欢
    • 2013-09-29
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 2013-02-17
    • 2015-06-09
    • 2014-08-08
    • 2013-08-28
    • 2019-04-20
    相关资源
    最近更新 更多