Tharaka
Tharaka

Reputation: 41

Display dynamically generated image inside JSF page

I have a JSF page which needs to display a dynamically generated image(using jfreeChart) located in the web folder. When the page is loaded it will display the previously generated image instead of the new image.The Image tag looks like as follows;

<h:graphicImage id="polarity" url="image.png" rendered="#{tweetController.renderedValue}/>

my image rendering method(This is invoked when the page load);

public void DisplayChart(Coreconf conf)
{
    this.conference = conf;
    GenerateImage();
    renderedValue = true;
}

The controller class has a method to create an image and both are invoked when the page is loaded. The problem, the image is loaded before the execution of the create new image method. Any suggestions?

Thanks, Tharaka

Upvotes: 1

Views: 719

Answers (1)

Tharaka
Tharaka

Reputation: 41

Finally, I found the solution. Although the creating dynamic image and the rendering h:graphicImage tag are excecuted at the same time, the creating image took more time than the rendering the image tag. Hence, the image tag rendered the old image. Adding a Thread sleep inside the image rendering fixed this issue.

public void DisplayChart(Coreconf conf)
{
    this.conference = conf;
    GenerateImage();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {
        Logger.getLogger(TweetController.class.getName()).log(Level.SEVERE, null, ex);
    }

    renderedValue = true;
}

Upvotes: 1

Related Questions