PF的graphicImage无法渲染 [英] PF's graphicImage doesn't render
问题描述
我正在使用JSF/PF,但我无法使graphicImage正常工作.回顾论坛上发布的大量主题,此PF的graphicImage似乎非常棘手.我显然做错了事,但是,只要我复制对其他人有用的代码(请参阅帖子),它一定是组件环境中的东西.我希望在这里找到一个解决方案,我陷入了数周的困境.谢谢
I'am using JSF/PF anf I can't make a graphicImage work. Reviewing the tons of topics published on forums, this PF's graphicImage seems to be so tricky. I am obviously doing somethig wrong, but, as long as I am replicating code that worked for others (see post), it must be something in the environment of the component. I hope to find a solution here, i'm stuck for weeks. Thanks
这是我在PF论坛中的原始问题:
Here is my original question in PF forum:
我在渲染图像时遇到问题.我已经按照说明的代码进行操作,并且可以正确检索图像的ID以在单独的方法中显示:
I encounter a problem rendering the image. I have followed the code explained and I correctly retrieve the id for image to display in a separate method:
public StreamedContent getStreamedImage() {
StreamedContent streamedImage = null;
UIViewRoot uiRoot = FacesContext.getCurrentInstance().getViewRoot();
System.out.println(uiRoot.getClientId());
UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent("itemDataForm:imagesTbl:itemImgComp");
Map attributes = component.getAttributes();
Integer image_id = (Integer)attributes.get("item_img_id");
if(image_id != null && editionItem != null && editionItem.getImages() != null){
for(ItemImageView img : editionItem.getImages()){
if(image_id.intValue() == img.getId()){
streamedImage = new DefaultStreamedContent(new ByteArrayInputStream(img.getImage()), "image/jpeg");
}
}
}else{
streamedImage = new DefaultStreamedContent(new ByteArrayInputStream(editionItem.getImages().get(0).getImage()), "image/jpeg");
}
.......
我无法设法检索(始终为null),所以我尝试使用attribute,它可以工作.因此,将加载DefaultStreamContent,因为图像根本不会呈现.我的xhtml代码:
I could't manage to retrieve the (always null) so I tried with attribute and it works. So, the DefaultStreamContent is loaded, by the image doesn't render at all. My code for xhtml:
<p:dataTable id="imagesTbl" var="itemImg" value="#{itemEditionBean.editionItem.images}">
<p:column>
<h:panelGrid columns="1">
<h:outputText value="#{itemImg.id}"/>
<p:graphicImage id="itemImgComp" value="#{itemEditionBean.streamedImage}">
<f:attribute name="item_img_id" value="#{itemImg.id}"/>
</p:graphicImage>
</h:panelGrid>
</p:column>
</p:dataTable>
与上述主题中的代码完全相同. PS:我在选项卡中包含了mt dataTable.也许依赖于封闭的组件,形式或什么?
Exactly the same that the code working in this topic above. PS: I have mt dataTable enclosed within a tab. Maybe a dependency on the enclosing component, or form, or what?
可以从下面的链接中查看来自其他相关主题的大量代码:
There is a huge amount of code from other related topics that can be viewed in the link below:
http://forum.primefaces.org/viewtopic.php?f = 3& t = 4163& p = 39751
推荐答案
基于我在显示动态图像的问题,但发现存在一个问题,它们与ConversationScoped bean结合使用了一个>.我将支持bean切换到Session作用域,现在可以正常工作了.
Based on another page I found on building dynamic images, <f:param .../>
should be used to supply a parameter to the getStreamedImage()
method rather than <f:attribute .../>
. Are you using a ConversationScoped backing bean? I was having the same problem displaying dynamic images, but found that there is a problem using them with ConversationScoped beans. I switched my backing bean to Session scope and now it works fine.
这篇关于PF的graphicImage无法渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!