[英]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.