2010-08-01 40 views
0

我的要求是以圖表格式顯示數據庫中的表格,並且我使用的是斐濟。並在這樣做我遇到和異常, 我的jsp頁面如下。使用斐濟(Exadel)庫的動態圖表&jsf

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:fiji="http://exadel.com/fiji"> 
    <fiji:columnChart id="columnChartOne" value="#{GraphBean.monthMap}" title="One-series Column Chart" barCaption="none" 
         barColors="#{GraphBean.colors}" captionX="Months" captionY="Amount" toolTipValue="{y} {name} are sold in {x}" 
         subtitle="Hardware sales per month" width="400" height="400"> 
     <fiji:chartData type="name" value="#{GraphBean.names}" /> 
    </fiji:columnChart> 
</ui:composition> 

我的豆如下:

import java.util.ArrayList; 
import java.util.Date; 
import java.util.LinkedHashMap; 
import java.util.Map; 
import java.util.Random; 


public class GraphBean { 

    private Integer data; 
    private Map<String, Integer> monthMap = new LinkedHashMap<String,Integer>(); 
    private ArrayList<String> names = new ArrayList<String>(); 
    private ArrayList<String> colors = new ArrayList<String>(); 
    Random rnd = new Random(new Date().getTime()); 

    public GraphBean() { 
     super(); 
     generateData(); 
    } 

    private void generateData() { 
     monthMap.put("January", getData()); 
     monthMap.put("February", getData()); 
     monthMap.put("March", getData()); 
    } 

    public Map<String, Integer> getMonthMap() { 
     return monthMap; 
    } 

    public ArrayList<String> getNames(){ 
     names.add("Motherboards"); 
     return names; 
    } 

    public ArrayList<String> getColors(){ 
     colors.add("#5db2c2"); 
     return colors; 
    } 

    public Integer getData() { 
     data = rnd.nextInt(50); 
     return data; 
    } 
} 

我已經爲在faces-config.xml中的豆條目。

+0

你的注意事項是什麼? 以及,如果您使用ui:composition,您可能正在編寫一個facelet頁面(xhtml)並且沒有jsp。 – Dejell 2010-08-01 08:49:34

+0

不,我正在使用jsp .........所以如何在jsp中做到這一點? – 2010-08-01 08:53:44

+0

你能寫出你的異常嗎? 以及如果我看到UI,如何使用jsp:表示facelet的構圖? – Dejell 2010-08-01 09:10:25

回答

1

在JSF中,你既可以用的facelet或JSP呈現頁面(雖然不推薦) 據我看到的,你要加載JSP頁面,同時加入了Facelet標記:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:fiji="http://exadel.com/fiji"> 
... 
</ui:composition> 

。如果您想使用facelet使用頁面,可以下載使用facelet here的示例。正如您所看到的,頁面的名稱後綴爲.xhtml,而不是.jsp。

如果你想使用JSP你的頁面必須是:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> 
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> 
    <%@ taglib uri="http://exadel.com/fiji" prefix="fiji" %> 

    <html> 
    <head> 
     <title>enter your name page</title> 
    </head> 
    <body> 
<f:view> 
      <fiji:columnChart id="columnChartOne" value="#{GraphBean.monthMap}" title="One-series Column Chart" barCaption="none" 
           barColors="#{GraphBean.colors}" captionX="Months" captionY="Amount" toolTipValue="{y} {name} are sold in {x}" 
           subtitle="Hardware sales per month" width="400" height="400"> 
       <fiji:chartData type="name" value="#{GraphBean.names}" /> 
      </fiji:columnChart> 
     </f:view> 
    </body> 
    </html> 

同樣,我會建議你使用的facelet,如果它是一個新的項目。

查看教程here

+0

Pssh,您的JSP示例無效。這裏仍然有一個'',你想把JSF組件包裝在''中。儘管如此,我們需要確定問題的要點:您不能將遺留JSP與其舊版Facelets混合使用。 – BalusC 2010-08-01 12:32:22

+0

@BalusC - 我編輯了我的答案。我只是複製他的代碼太快 – Dejell 2010-08-01 12:48:22

+0

感謝戰利品Odelya&BalusC似乎你都知道每一個。我只是一個無知的孩子.............再次感謝您寶貴的時間。 – 2010-08-01 18:22:19