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;

}

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