PF的graphicImage不渲染

发布于 2024-11-17 03:16:43 字数 2491 浏览 1 评论 0 原文

我正在使用 JSF/PF,但我无法使图形图像工作。回顾论坛上发表的大量主题,这个PF的graphicImage似乎很棘手。我显然做错了一些事情,但是,只要我复制对其他人有用的代码(请参阅帖子),它就一定是组件环境中的东西。我希望在这里找到解决方案,我被困了几周。谢谢

这是我在 PF 论坛中的原始问题:

我遇到渲染图像的问题。我已按照解释的代码进行操作,并且正确检索了要在单独的方法中显示的图像的 id:

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");
        }
.......

我无法设法检索(始终为空),因此我尝试使用属性并且它有效。因此,DefaultStreamContent 已加载,但图像根本不渲染。我的 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 包含在选项卡中。也许是对封闭组件、表单或其他什么的依赖?

其他相关主题的大量代码可以在下面的链接中查看:

http://forum.primefaces.org/viewtopic.php?f=3&t=4163&p=39751

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

Here is my original question in PF forum:

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");
        }
.......

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>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪若未夕 2024-11-24 03:16:43

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文