我是Java Web的新手。我正在使用netbeans 7.0.1和glassfish 3開發一個Web應用程序。我幾乎通過所有的數據輸入,現在我想創建報告&圖。要求是使用動態數據(來自數據庫/數據表用戶可以對數據應用過濾器)創建圖表(基於用戶選擇的餅圖/欄/線)。我嘗試使用Primefaces但它給下面的錯誤與primeface出現在給出簡單的例子:如何在java web應用程序中創建圖表
javax.faces.event.AbortProcessingException: /pages/analyst/analyse.xhtml @65,151 actionListener="#{analysis.bar()}": java.lang.NoClassDefFoundError: org/primefaces/component/chart/series/ChartSeries
我有持有的DataTable通過viewscope的managedbean支持的JSF頁面。下面是我的代碼:
頁
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<ui:composition template="./../../WEB-INF/Templates/VUTemplate.xhtml">
<ui:define name="menu">
<h:form id="home">
<p:menu>
<p:menuitem value="Home Page" url="../home.xhtml" />
</p:menu>
</h:form>
</ui:define>
<ui:define name="content">
<h:form id="form" prependId="false">
<p:growl id="growl" showDetail="true"/>
<p:barChart id="basic" value="#{analysis.categoryModel}" legendPosition="ne"
title="Basic Bar Chart" min="0" max="200" style="height:300px"/>
<p:dataTable id="table" var="var" widgetVar="wbTable"
value="#{analysis.list}"
paginator="true" rows="10"
paginatorPosition="bottom"
emptyMessage="No data found with given criteria"
>
<f:facet name="header">
World Bank Open Data Analysis
</f:facet>
<p:column filterBy="#{var.regionFullName}" sortBy="#{var.regionFullName}"
headerText="Region" footerText="Enter starting characters" >
<h:outputText value="#{var.regionFullName}" />
</p:column>
<p:column filterBy="#{var.countryFullName}" sortBy ="#{var.countryFullName}"
headerText="Country" footerText="Enter starting characters" >
<h:outputText value="#{var.countryFullName}" />
</p:column>
<p:column filterBy="#{var.indcatorTypeName}" sortBy ="#{var.indcatorTypeName}"
headerText="Indicator Type" footerText="Enter starting characters" >
<h:outputText value="#{var.indcatorTypeName}" />
</p:column>
<p:column filterBy="#{var.indicatorName}" sortBy ="#{var.indicatorName}"
headerText="Indicator" footerText="contains" filterMatchMode="contains">
<h:outputText value="#{var.indicatorName}" />
</p:column>
<p:column filterBy="#{var.year}" sortBy ="#{var.year}"
headerText="Year" footerText="starts with">
<h:outputText value="#{var.year}" />
</p:column>
<p:column filterBy="#{var.dataValue}" sortBy ="#{var.dataValue}"
headerText="Data Value" footerText="starts with" >
<h:outputText value="#{var.dataValue}" />
</p:column>
</p:dataTable>
<h:panelGrid id="command" columns="6" cellpadding="4" >
<p:commandButton id="line" value="Line" actionListener="#{analysis.line()}" process="@this :form:table" update="result table" >
</p:commandButton>
<p:commandButton id="bar" value="Bar" actionListener="#{analysis.bar()}" process="@this :form:table" update="result table" >
</p:commandButton>
</h:panelGrid>
<p:messages id="result" showDetail="true" autoUpdate="true"/>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
backbean
import ejb.VwdataFacade;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import model.Vwdata;
import org.primefaces.component.chart.series.ChartSeries;
import org.primefaces.model.chart.CartesianChartModel;
@ManagedBean
@ViewScoped
public class Analysis implements Serializable{
private List<Vwdata> list;
private @EJB VwdataFacade wsvc; //entity services
private CartesianChartModel categoryModel;
public Analysis() {
}
public CartesianChartModel getCategoryModel() {
return categoryModel;
}
@PostConstruct
public void init() {
list = wsvc.findAll();
}
public List<Vwdata> getList() {
// list = wsvc.findAll();
return list;
}
public void line(){
}
public void bar(){
createCategoryModel();
}
private void createCategoryModel() {
categoryModel = new CartesianChartModel();
ChartSeries yaxis = new ChartSeries();
yaxis.setLabel("Label");
yaxis.set("2004",120);
yaxis.set("2005",130);
yaxis.set("2006",140);
yaxis.set("2007",110);
categoryModel.addSeries(yaxis);
}
}
如果我把調用createCategoryModel在構造函數或init方法,我不能甚至有觀點認爲,否則是完美的工作,而不圖表頁面碼。任何幫助將不勝感激。謝謝
如果刪除圖表,您的頁面是否可以正確加載? –