【问题标题】:PF's graphicImage doesn't renderPF的graphicImage不渲染
【发布时间】:2011-06-26 12:53:50
【问题描述】:

我正在使用 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

【问题讨论】:

  • 请在此处发布原始问题。

标签: jsf primefaces


【解决方案1】:

基于我在building dynamic images 上找到的另一个页面,&lt;f:param .../&gt; 应该用于为getStreamedImage() 方法提供参数,而不是&lt;f:attribute .../&gt;。您是否使用 ConversationScoped 支持 bean?我有相同的problem displaying dynamic images,但发现有一个problem using them with ConversationScoped beans。我将我的支持 bean 切换到 Session 范围,现在它工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-20
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 2020-09-17
    相关资源
    最近更新 更多