Hi guys,
I have some problem implementing an open source cewolf software into my program. I need to generate graph based on result that is getting from database selection (anotner class). Then I passed the result in a session to the graph class. But it seems that the class cannot read the session value. Below I paste my jsp and my class. Java error message is also paste below.
Hope any experts out there can help me.
zamir
Java Error Messages:
[code]
java.lang.ClassCastExcepti
on
at de.laures.cewolf.example.P
ageViewCou
ntData.pro
duceDatase
t(PageView
CountData.
java:64)
at de.laures.cewolf.taglib.Da
taContaine
r.getDatas
et(DataCon
tainer.jav
a:53)
at de.laures.cewolf.taglib.Si
mpleChartD
efinition.
getDataset
(SimpleCha
rtDefiniti
on.java:34
)
at de.laures.cewolf.taglib.ut
il.PageUti
ls.getData
set(PageUt
ils.java:5
8)
at de.laures.cewolf.taglib.ta
gs.ChartMa
pTag.doSta
rtTag(Char
tMapTag.ja
va:71)
[/code]
myjsp:
[code]
<%@taglib uri='/WEB-INF/cewolf.tld' prefix='cewolf' %>
<%@taglib uri="/WEB-INF/struts-html.
tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-bean.
tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-logic
.tld" prefix="logic" %>
<%@page import="eplan.graph.busine
ss.*" %>
<%@page import="java.io.Serializab
le"%>
<% //Object theObj = session.getAttribute("theO
bjectsName
") %>
<% HttpSession getSession= request.getSession(false);
%>
<% GraphByFruit[] theObj = (GraphByFruit[])session.ge
tAttribute
("GraphDat
a");%>
<% //System.out.print("GraphB
yFruit[] theObj ="+theObj+"\n");%>
<jsp:useBean id="categoryDataGraph" class="de.laures.cewolf.ex
ample.Page
ViewCountD
ata"/>
<!-- Bar Graph -->
<p>
<div align="center">
<cewolf:chart id="horizontalBarChart" title="Anggaran Pengeluaran Buah-Buahan Bermusim" type="horizontalBar" xaxislabel="Mont$
<cewolf:data>
<cewolf:producer id="categoryDataGraph">
<cewolf:param name="graphSession" value="<%=theObj%>"/>
<!--cewolf:param name="graphSession" value='<%//=(GraphByFruit)
session.ge
tAttribute
("GraphDat
a") %>'/-->
</cewolf:producer>
</cewolf:data>
</cewolf:chart>
<cewolf:img chartid="horizontalBarChar
t" renderer="cewolf" width="750" height="500">
<cewolf:map tooltipgeneratorid="catego
ryToolTipG
enerator" linkgeneratorid="categoryL
ink"/>
</cewolf:img>
</div>
</p>
[/code]
myclass:
[code]
package de.laures.cewolf.example;
import java.util.Date;
import java.util.Map;
import java.io.Serializable;
import org.jfree.data.CategoryDat
aset;
import org.jfree.data.DefaultCate
goryDatase
t;
import de.laures.cewolf.DatasetPr
oduceExcep
tion;
import de.laures.cewolf.DatasetPr
oducer;
import de.laures.cewolf.CategoryI
temLinkGen
erator;
import org.apache.commons.logging
.Log;
import org.apache.commons.logging
.LogFactor
y;
import org.jfree.chart.tooltips.C
ategoryToo
lTipGenera
tor;
import eplan.graph.business.Graph
ByFruit;
import javax.servlet.http.*;
/**
* An example data producer.
* @author Guido Laures
* @modified by Zamir A Jalil
*/
public class PageViewCountData implements DatasetProducer,CategoryIt
emLinkGene
rator,Cate
goryToolTi
pGenerator
,Serializa
ble
{
private static final Log log = LogFactory.getLog(PageView
CountData.
class);
// These values would normally not be hard coded but produced by
// some kind of data source like a database or a file
private final String[] categories = {"mon","tue","wen","thu","
fri","sat"
,"sun","mo
n","tue","
wen","thu"
,"fri"};
String[] arrayOfFruit;
/**
* Produces some random data.
*/
public Object produceDataset(Map params) throws DatasetProduceException {
int month = 0;
float[] qty = null;
System.out.print ("\n\n/*******************
**********
**********
**********
**********
***/\n");
HttpSession graphsession = (HttpSession)params.get("g
raphSessio
n");
//System.out.print ("HttpSession graphsession ="+graphsession+"\n");
GraphByFruit[] graph = (GraphByFruit[])graphSessi
on.getAttr
ibute("Gra
phData");;
final String[] arrayOfFruit = new String[graph.length];
log.debug("producing data.");
DefaultCategoryDataset datagraph = new DefaultCategoryDataset(){
/**
* @see java.lang.Object#finalize(
)
*/
protected void finalize() throws Throwable {
super.finalize();
log.debug(this +" finalized.");
}
};
for (int series = 0; series < arrayOfFruit.length; series ++) {
arrayOfFruit[series] = graph[series].getFruitName
();
qty = graph[series].getProdQty()
;
float[] lastY = qty;
for (int i = 0; i < categories.length; i++) {
final float y = qty[i];
//lastY = y;
datagraph.addValue((double
)y, arrayOfFruit[series], categories[i]);
}
}
return datagraph;
}
/**
* This producer's data is invalidated after 5 seconds. By this method the
* producer can influence Cewolf's caching behaviour the way it wants to.
*/
public boolean hasExpired(Map params, Date since) {
log.debug(getClass().getNa
me() + "hasExpired()");
return (System.currentTimeMillis(
) - since.getTime()) > 5000;
}
/**
* Returns a unique ID for this DatasetProducer
*/
public String getProducerId() {
return "GraphSessionDataSetProduc
er";
}
/**
* Returns a link target for a special data item.
*/
public String generateLink(Object data, int series, Object category) {
return arrayOfFruit[series];
}
/**
* @see java.lang.Object#finalize(
)
*/
protected void finalize() throws Throwable {
super.finalize();
log.debug(this + " finalized.");
}
/**
* @see org.jfree.chart.tooltips.C
ategoryToo
lTipGenera
tor#genera
teToolTip(
CategoryDa
taset, int, int)
*/
public String generateToolTip(CategoryDa
taset arg0, int series, int arg2) {
return arrayOfFruit[series];
}
}
[/code]