我是primefaces的新手。当我生成 PieChart 即使用静态或示例信息设置 PieChartModel 时,它工作正常,但是当我使用数据库中的数据时,它给了我 java.lang.NullPointerException
我的豆子
public class ChartControllerPie {
@EJB
private session.SubscribeFacade ejbsubscribe;
public List<String> v() {
return ejbsubscribe.allVille();
}
private PieChartModel pieModel;
public ChartControllerPie() {
createPieModel();
}
public PieChartModel getPieModel() {
return pieModel;
}
private void createPieModel() {
pieModel = new PieChartModel();
pieModel.set("bouhajla", 1540);
pieModel.set("meknasi", 325);
pieModel.set("mater", 702);
pieModel.set("najta", 421);
}
}
此方法返回结果
@EJB
private session.SubscribeFacade ejbsubscribe;
public List<String> v() {
return ejbsubscribe.allVille();
}
但是当我添加这个 v(); ???不工作我的豆
public class ChartControllerPie {
@EJB
private session.SubscribeFacade ejbsubscribe;
public List<String> v() {
return ejbsubscribe.allVille();
}
private PieChartModel pieModel;
public ChartControllerPie() {
createPieModel();
}
public PieChartModel getPieModel() {
return pieModel;
}
private void createPieModel() {
pieModel = new PieChartModel();
v();// for use data
pieModel.set("bouhajla", 1540);
pieModel.set("meknasi", 325);
pieModel.set("mater", 702);
pieModel.set("najta", 421);
}
}
只是问题是从数据库创建 PieChartModel
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="statistiquefaces.xhtml">
<ui:define name="title">
</ui:define>
<ui:define name="centre">
<p:pieChart id="custom" value="#{chartControllerPie.pieModel}" legendPosition="e" fill="false" showDataLabels="true"
title="Custom Options" style="width:400px;height:300px" sliceMargin="5" diameter="150" />
</ui:define>
</ui:composition>
</html>