简体   繁体   English

流动态资源出错。 将p:graphicImage与Primefaces一起使用

[英]Error in streaming dynamic resource. Using p:graphicImage with Primefaces

I'm trying to dynamically display an image in primefaces using the p:graphicImage tag as follows: 我正在尝试使用p:graphicImage标记在primefaces中动态显示图像,如下所示:

<p:graphicImage value="#{submissionBean.contestImage}">
    <f:param name="imageName"
        value="#{contestBean.createContest.submissions[0].fileName}" />
</p:graphicImage>`

The managed bean is as follows: 托管bean如下:

@ManagedProperty("#{param.imageName}")
private String imageName;

public String getImageName()
{
    return imageName;
}

public void setImageName(String imageName)
{
    this.imageName = imageName;
}

private StreamedContent contestImage;

public StreamedContent getContestImage()
{
    FacesContext context = FacesContext.getCurrentInstance();
    if (imageName == null)
        imageName = Constants.SUBMISSION_FILE_DIR + "/" + "sacxzx_asdsdaas_icon.png";
    if (context.getRenderResponse())
    {
        // So, we're rendering the view. Return a stub StreamedContent so
        // that it will generate right URL.
        return new DefaultStreamedContent();
    }
    else
    {

        return new DefaultStreamedContent(this.getClass().getResourceAsStream(Constants.SUBMISSION_FILE_DIR + "/" + imageName));
    }
}

I'm always getting the error of "SEVERE: Error in streaming dynamic resource." 我总是得到“SEVERE:流动态资源错误”的错误。

Checking the URL for the image seems just fine: 检查图像的URL似乎很好:

http://localhost:8080/mashup/javax.faces.resource/dynamiccontent.xhtml?ln=primefaces&pfdrid=pfdrid_4290aa0c-8eef-45ea-a281-638e460e33bf&imageName=sacxzx_asdsdaas_icon.png

Any idea why this is? 知道为什么会这样吗?

Thanks! 谢谢!

Should be SessionScoped . 应该是SessionScoped As method getContestImage() is called multiple times during page processing, it is better to create the stream only once. 由于方法getContestImage()在页面处理期间被多次调用,因此最好只创建一次流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 流动态资源出错。 空值 - Error in streaming dynamic resource. null 尝试使用 PrimeFaces 下载内容时出错<p:filedownload> java.io.IOException:流式动态资源异常中的错误</p:filedownload> - Error trying to download content with PrimeFaces <p:fileDownload> java.io.IOException: Error in streaming dynamic resource Exception primefaces 4.0 p:graphicimage defaultstreamedcontent不呈现 - primefaces 4.0 p:graphicimage defaultstreamedcontent does not render 如何显示替代文字 <p:graphicImage> 在PrimeFaces? - How to display alternate text on <p:graphicImage> in PrimeFaces? graphicImage不使用jsf和primefaces收费 - graphicImage does not charge using jsf and primefaces 如何将服务器路径图像显示到PrimeFaces p:graphicImage? - How to show the server path image to PrimeFaces p:graphicImage? 在标记文件中使用p:graphicImage显示BLOB图像 - Display a BLOB image using p:graphicImage in a tagfile 如何渲染 <p:graphicImage> 有条件地取决于资源是否存在 - How to render <p:graphicImage> conditionally depending on if the resource exists 使用 p:graphicImage 和 StreamedContent 显示来自数据库或远程源的动态图像 - Display dynamic image from database or remote source with p:graphicImage and StreamedContent 如何使用p:graphicImage在p:dataGrid中显示图像 - How to show images in p:dataGrid using p:graphicImage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM