Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsf

primefaces

I'm trying to dynamically display an image in primefaces using the p:graphicImage tag as follows:

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

The managed bean is as follows:

@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."

Checking the URL for the image seems just fine:

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!

like image 794
Graeme Avatar asked Aug 17 '12 18:08

Graeme


1 Answers

Should be SessionScoped. As method getContestImage() is called multiple times during page processing, it is better to create the stream only once.

like image 136
Mato Avatar answered Oct 05 '22 04:10

Mato