我是 Java Web 的新手。我正在使用 netbeans 7.0.1 和 glassfish 3 来开发 Web 应用程序。我几乎完成了所有数据输入,现在我想创建报告和图表。要求是使用动态数据(来自数据库/数据表的用户可以对数据应用过滤器)创建图表(基于用户选择的饼图/条形图/线)。我尝试使用 Primefaces,但它给出了以下错误,并在 primeface 展示案例中给出了简单的示例:
javax.faces.event.AbortProcessingException: /pages/analyst/analysis.xhtml @65,151 actionListener="#{analysis.bar()}": java.lang.NoClassDefFoundError: org/primefaces/component/chart/series/ChartSeries
我有一个 jsf 页面,其中包含由 viewscope 的 managedbean 支持的数据表。下面是我的代码:
页
<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>
豆豆
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);
}
}
如果我在构造函数或 init 方法中调用 createCategoryModel,我什至无法查看在没有图表代码的情况下可以正常工作的页面。任何帮助将不胜感激。谢谢