Primefaces p:graphicImage dynamicContent 无法加载 404

如何解决Primefaces p:graphicImage dynamicContent 无法加载 404

显示 p:graphicImage 动态内容已经让我忙了好几天了。任何人都可以帮助我,我将非常感激。

我有一个简单的 p:graphicImage 方法作为 imgage.jpg 的 StreamedContent 加载到列表 (TreeMap) 中。

这是我的 xhtml 片段:

            <p:dataView var="id"
                value="#{fotoViewer.imagesViewTree.entrySet()}"
                    gridIcon="pi pi-th-large" listIcon="pi pi-bars">

            <p:dataViewListItem>
                <h:panelGrid columns="2" style="width:100%" columnClasses="">

                    <p:graphicImage value="#{id.value.streamedImage}"
                        style="max-width: 30vw; max-height: 53vh;" cache="false"
                        stream="true" styleClass="w3-round-xlarge" />

                    <p:outputPanel>
                        <h:panelGrid columns="2" cellpadding="5">
                            <h:outputText value="Id:" />
                            <h:outputText value="#{id.key}" style="font-weight: bold" />

                            <h:outputText value="naam:" />
                            <h:outputText value="#{id.value.naam}" style="font-weight: bold" />

                        </h:panelGrid>
                    </p:outputPanel>

                </h:panelGrid>
            </p:dataViewListItem>
        </p:dataView>

我可以看到位于浏览器中的 dynamicContents 就可以判断而言看起来不错,它是:

(img id="cac010:j_id_11:0:j_id_14" src="/cJsfComponents1/faces/javax.faces.resource/dynamiccontent.properties?ln=primefaces&v=8.0&pfdrid=8ca67d0788631c681bridedpcfbfc8fcdpfc8fcfbfcdpfc8fc8fcdpfcfbfc8fc8fc8fcfcfcfc8211cdee9 -4b5f-80b8-b7868dac9f10" alt="" class="w3-round-xlarge" style="max-width: 30vw; max-height: 53vh;")

我不明白为什么服务器不提供 contentStream。它以 http-status-code-404 响应。

如有任何帮助,请提前感谢!

解决方法

找到了 8 多年前给出的解决方案,这正是我一直在寻找的地方。而且……效果很好!

如何在 ui:repeat 中使用 和 DefaultStreamedContent?

How to use <p:graphicImage> with DefaultStreamedContent in an ui:repeat?

自从我使用 PrimeFaces V8.0 以来,关于如何获取图像的 StreamedContent 有一些不同的实现。这是我的 ImageStreamer 方法:

public StreamedContent getStreamedContentOfImage(ByteArrayInputStream bais) {
    StreamedContent graphicImage = null;
    graphicImage = DefaultStreamedContent.builder().contentType("image/png").stream(() -> {
        try {
            return bais;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }).build();

    return graphicImage;

}

也许它可以帮助将来的某个人!?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?