Sarroura
Sarroura

Reputation: 553

Force reload image jsf

I would like to display a graphic image in a jsf web application from a html file that's changing for each run. The problem is that the displayed image was always the same.

I tried to solve this by generating a random number at the end of the image name.

    public String getImageId () {
    String imageId = ""; 
    int nb = (int)Math.random(); 
    imageId = "?id="+Integer.toString(nb);
    return imageId; 
}

Then, I call it in my jsf page

<h:graphicImage value="/images/Report.html_files/img_0_0_0#{MyBean.imageId}" cacheable="false" />

But nothing change.

Do you Have any idea about this ? Thanks

Upvotes: 0

Views: 1468

Answers (2)

Renato Pradebon
Renato Pradebon

Reputation: 2093

Another palliative solution, is force refresh in your browser using the keys CTRL + SHIFT + R.

Upvotes: 0

Simon C
Simon C

Reputation: 2017

For my application, I created a Java Servlet that returns a different image each time, with HTTP header Cache-Control set to prevent caching and I use the servlet URL in my JSF tag.

I do not think you can dynamically change the image with a URL to a static file, like in your example.

Upvotes: 2

Related Questions