【问题标题】:Primefaces p:graphicImage dynamicContent failed to load 404Primefaces p:graphicImage 动态内容无法加载 404
【发布时间】:2021-04-15 11:42:51
【问题描述】:

显示 p:graphicImage 动态内容让我已经忙了好几天了。谁能帮帮我,我将不胜感激。

我有一个直接的 p:graphicImage 方法,将 imgage.jpg 的 StreamedContent 加载到一个列表(TreeMap)中。

这是我的 xhtml sn-p:

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

我可以在我的浏览器中看到动态内容,就可以判断而言,它看起来不错,这里是:

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

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

提前感谢您的帮助!

【问题讨论】:

标签: primefaces http-status-code-404 dynamic-content graphicimage


【解决方案1】:

找到了 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;

}

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

【讨论】:

    【解决方案2】:

    @tandraschko:感谢您的快速回复。您包含的链接是几天前的,也是我的起点。我必须说helas,这是一个非常糟糕的例子!该代码不起作用并且不完整。链接How to use <p:graphicImage> with DefaultStreamedContent in an ui:repeat? 让我走上了正轨。我现在一切都很好,而且我对 PrimeFaces 越来越热情!遗憾的是,并非所有文档都是准确、实际和清晰的设置,并考虑到所有级别的用户!无论如何谢谢!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-13
    • 2013-03-29
    • 2013-09-13
    • 2011-06-14
    • 2014-02-23
    相关资源
    最近更新 更多