我无法使基本的primefaces饼图工作。 即时通讯使用primefaces 4.0,eclipse kepler和glassfish 4.0 我得到的错误是:
java.lang.ClassCastException: java.lang.String cannot be cast to org.primefaces.model.chart.PieChartModel
XHTML:
<p:pieChart value="chart.model" legendPosition="w" />
爪哇:
package server;
import org.primefaces.model.chart.PieChartModel;
import javax.annotation.PostConstruct;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
public class Chart implements Serializable
{
private static final long serialVersionUID = 1L;
private PieChartModel model;
public Chart()
{
model = new PieChartModel();
model.set("Brand1", 540);
model.set("Brand2", 325);
model.set("Brand3", 702);
model.set("Brand4", 421);
}
public PieChartModel getModel()
{
return model;
}
}
任何想法我做错了什么? 感谢
答案 0 :(得分:0)
您的错误来自:
<p:pieChart value="chart.model" legendPosition="w" />
您的价值应为:value="#{chartBean.chart.model}"
其中chartBean是带注释的ManagedBean。
@ManagedBean(name="chartBean")
@YOURSCOPE (might be Request, Session etc...)
public class ChartBean implements Serializable{
Chart chart;
//you should initialize your bean in the constructor, or somewhere in the class, like
public ChartBean(){
...
Chart = new Chart();
...
}
public Chart getChart(){
return this.chart;
}
}