2014-03-19 67 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