2014-03-19 70 views
1

我有一个JSF页面需要显示位于web文件夹中的动态生成图像(使用jfreeChart)。当页面加载时,它将显示先前生成的图像,而不是新的图像。图像标记如下所示:在JSF页面显示动态生成的图像

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

我的图片渲染方法(这是在页面加载的时候调用的);

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

控制器类有一个方法来创建一个图像,并加载页面时调用。问题是,图像在执行create new image方法之前被加载。有什么建议么?

感谢, Tharaka

回答

1

最后,我找到了解决办法。尽管创建动态图像和渲染h:graphicImage标记同时执行,但创建图像比渲染图像标记需要更多的时间。因此,图像标签呈现旧图像。在图像渲染中添加线程睡眠解决了此问题。

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; 
} 
+0

似乎是一种黑客......他们是否同时运行? - 请参阅:http://stackoverflow.com/questions/15389857/jsf-lazy-loading-component-value potentialy可能会帮助您强制您的网页睡眠2秒,同时生成图像 – VeenarM