本文介绍了无法在 p:graphicImage 中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我可以在 ui:repeat 部分看到图像,但是当我单击图像时,命令链接和 setPropertyActionListener 工作正常,但图像没有显示在所需的面板网格中.

</h:panelGroup></h:panelGrid></p:layoutUnit><p:layoutUnit id="left" position="west" ><h:panelGrid id="panelGrid3" columns="2" cellspacing="2" cellpadding="2"><ui:repeat id="repeat5" value="#{getData.imageThumbnail1}" var="imagesLst" varStatus="loop"><h:面板组><p:commandLink update=":form:tabView:test" ><f:setPropertyActionListener target="#{imageController.imageID}" value="#{imagesLst.imageID}"/><p:graphicImage id="gi5" value="#{imagesStreamer.image}" alt="图像不可用" ><f:param name="id" value="#{imagesLst.imageID}"/></p:graphicImage></p:commandLink></h:panelGroup></ui:repeat></h:panelGrid></p:layoutUnit>

支撑豆

@ManagedBean@SessionScoped公共类 imageController 实现了 Serializable {私人字符串图像ID;私有流内容 sc;/** 创建一个新的 imageController 实例 */公共图像控制器(){}public void setImageID(String imageID) {this.imageID = imageID;System.out.println("ImageController set == "+ this.imageID);}公共字符串 getImageID(){返回图像ID;}公共流内容 getImage() {System.out.println("ImageController get == "+ this.imageID);如果(图像ID!= null){ByteArrayInputStream image = GetData.findImages(imageID);System.out.println("传递默认流内容");返回新的 DefaultStreamedContent(image);}返回 sc;}}

无法加载图像 #{imageController.imageID}"与所选图像 ID 一起显示,但我在图形面板中看不到该图像.在日志中我也没有看到任何错误消息,它返回流式内容.

更新代码:1

</h:panelGroup></h:panelGrid></p:layoutUnit><p:layoutUnit id="right" position="east" ><h:panelGrid id="panelGrid3" columns="2" cellspacing="2" cellpadding="2"><ui:repeat id="repeat5" value="#{getData.imageThumbnail1}" var="imagesLst" varStatus="loop"><h:面板组><p:commandLink id="cl5" update=":form:tabView:test"><p:graphicImage id="gi5" value="#{imagesStreamer.image}" alt="image not available3" ><f:param name="id5" value="#{imagesLst.imageID}"/></p:graphicImage></p:commandLink></h:panelGroup></ui:repeat></h:panelGrid></p:layoutUnit>

解决方案

替换

<p:graphicImage id="prodImage" value="#{imageController.image}" alt="无法加载图片#{imageController.imageID}"/>

<p:graphicImage id="prodImage" value="#{imagesStreamer.image}" alt="无法加载图片#{imageController.imageID}"><f:param name="id" value="#{imageController.imageID}"/></p:graphicImage>

删除那个 ImageController#getImage() 方法.继续对所有动态图像使用 ImageStreamer(假设您使用了 您之前的问题之一).

I have the following code, i can see images in the ui:repeat part but when i click on the image the command link and setPropertyActionListener works fine but the image does not get displayed in the required panel grid.

<p:layoutUnit id="centre" position="center"  >
    <h:panelGrid id="test" columns="2" cellpadding="2" >
        <h:panelGroup>
            <div id="imageWrap" style="width:600px; height:400px; margin:auto; overflow:scroll; position:relative;">
                <p:graphicImage id="prodImage" value="#{imageController.image}" alt="unable to load image #{imageController.imageID}" />
            </div>
        </h:panelGroup>
    </h:panelGrid>
</p:layoutUnit>

<p:layoutUnit id="left" position="west" >
    <h:panelGrid  id="panelGrid3" columns="2" cellspacing="2" cellpadding="2">
        <ui:repeat id="repeat5" value="#{getData.imageThumbnail1}" var="imagesLst" varStatus="loop">
            <h:panelGroup>
                <p:commandLink update=":form:tabView:test" >
                    <f:setPropertyActionListener target="#{imageController.imageID}" value="#{imagesLst.imageID}" />
                    <p:graphicImage id="gi5" value="#{imagesStreamer.image}" alt="image not available" >
                        <f:param name="id" value="#{imagesLst.imageID}" />
                    </p:graphicImage>
                </p:commandLink>
            </h:panelGroup>
        </ui:repeat>
    </h:panelGrid>
</p:layoutUnit>

the supporting bean

@ManagedBean
@SessionScoped
public class imageController implements Serializable {

    private String imageID;
    private StreamedContent sc;

    /** Creates a new instance of imageController */
    public imageController() {
    }

    public void setImageID(String imageID) {
        this.imageID = imageID;
        System.out.println("ImageController set == "+ this.imageID);
    }

    public String getImageID(){
        return imageID;
    }

    public StreamedContent getImage() {
        System.out.println("ImageController get == "+ this.imageID);
        if (imageID != null) {
            ByteArrayInputStream image = GetData.findImages(imageID);
            System.out.println("Passing Default Streamed Content");
            return new DefaultStreamedContent(image);
        }
        return sc;

    }
}

The "unable to load image #{imageController.imageID}" is displayed with the selected image id but i cannot see the image in the graphic panel.In the log also i don't see any error message, it returns the streamedcontent.

UPDATED CODE:1

<p:layoutUnit id="centre" position="center"  >
    <h:panelGrid id="test" columns="2" cellpadding="2" >
        <h:panelGroup>
            <div id="imageWrapper" style="width:600px; height:400px; margin:auto; overflow:scroll; position:relative;">
                <p:graphicImage id="Img1" value="#{imagesStreamer.image}" alt="image id to be displayed #{imagesLst.imageID}" >
                    <f:param name="id5" value="#{imagesLst.imageID}" />
                </p:graphicImage>
            </div>
        </h:panelGroup>
    </h:panelGrid>
</p:layoutUnit>

<p:layoutUnit id="right" position="east" >
    <h:panelGrid  id="panelGrid3" columns="2" cellspacing="2" cellpadding="2">
        <ui:repeat id="repeat5" value="#{getData.imageThumbnail1}" var="imagesLst" varStatus="loop">
            <h:panelGroup>
                <p:commandLink id="cl5" update=":form:tabView:test">
                    <p:graphicImage id="gi5" value="#{imagesStreamer.image}" alt="image not available3" >
                        <f:param name="id5" value="#{imagesLst.imageID}" />
                    </p:graphicImage>
                </p:commandLink>
            </h:panelGroup>
        </ui:repeat>
    </h:panelGrid>
</p:layoutUnit>
解决方案

Replace

<p:graphicImage id="prodImage" value="#{imageController.image}" alt="unable to load image #{imageController.imageID}" />

by

<p:graphicImage id="prodImage" value="#{imagesStreamer.image}" alt="unable to load image #{imageController.imageID}">
    <f:param name="id" value="#{imageController.imageID}" />
</p:graphicImage>

and remove that ImageController#getImage() method. Keep using the ImageStreamer for all dynamic images (assuming that you used the one as provided in one of your previous questions).

这篇关于无法在 p:graphicImage 中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:49