显示p:graphicImage动态内容已经让我忙了好几天了。有没有人能帮我,我会很感激的。
我有一个直接的方法p:graphicImage as StreamedContent of imgage.jpg加载到一个列表中(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 src="/cJsfComponents1/faces/javax.faces.resource/dynamiccontent.properties?ln=primefaces&v=8.0&pfdrid=8ca67d0788631c82cdee936b119abf8e&pfdrt=sc&pfdrid_c=false&uid=6d617a80-1fe2-4b5f-80b8-b7868dac9f10“”cac010:j_id_11:0:j_id_14“id= alt="”class=“w3-cac010:j_id_11:0:j_id_14-X xlarge”style="max-width: 30vw;max-height: 53vh;")
我不明白为什么服务器不提供contentStream。它以http-status-code-404作为响应。
如有任何帮助,请提前向我咨询!
发布于 2021-01-11 03:35:18
找到了8年前给出的解决方案,这正是我正在寻找的。还有……它工作得很好!
如何在ui中使用带有DefaultStreamedContent的:重复?
How to use 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;
}
也许它能在未来帮助别人!?
发布于 2021-01-13 02:51:32
@tandraschko:感谢您的快速回复。你包含的链接几天前也是我的起点。我必须说,你好,这是一个非常糟糕的例子!代码不工作并且不完整。链接How to use with DefaultStreamedContent in an ui:repeat?让我走上了正确的道路。我现在已经把一切都做得很好了,而且我越来越热衷于使用PrimeFaces了!遗憾的是,并不是所有的文档都是准确、实际和清晰的设置,并且考虑到了所有级别的用户!不管怎么说,谢谢!
https://stackoverflow.com/questions/65651483
复制相似问题