无法在p:graphicImage中显示图像

时间:2012-06-13 11:58:14

标签: jsf-2 primefaces

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

<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>

支持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;

    }
}

显示“无法加载图像#{imageController.imageID}”,其中包含所选图像ID,但我无法在图形面板中看到图像。 在日志中我也没有看到任何错误消息,它返回了streamedcontent。

更新代码: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>

1 个答案:

答案 0 :(得分:0)

替换

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

通过

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

删除 ImageController#getImage()方法。继续对所有动态图像使用ImageStreamer(假设您使用了one of your previous questions中提供的图像)。