1

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

Tharaka
  • 41
  • 4

1 Answers1

1

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;
}
Tharaka
  • 41
  • 4
  • seems kind of hackey... are they running concurrently? - See: http://stackoverflow.com/questions/15389857/jsf-lazy-loading-component-value potentialy may help you with out forcing your webpage to sleep for 2 seconds while an image is generated – VeenarM Mar 20 '14 at 06:10