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.ClassCastException
at de.laures.cewolf.example.PageViewCountData.produceDataset(PageViewCountData.java:64)
at de.laures.cewolf.taglib.DataContainer.getDataset(DataContainer.java:53)
at de.laures.cewolf.taglib.SimpleChartDefinition.getDataset(SimpleChartDefinition.java:34)
at de.laures.cewolf.taglib.util.PageUtils.getDataset(PageUtils.java:58)
at de.laures.cewolf.taglib.tags.ChartMapTag.doStartTag(ChartMapTag.java: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.business.*" %>
<%@page import="java.io.Serializable"%>
<% //Object theObj = session.getAttribute("theObjectsName") %>
<% HttpSession getSession= request.getSession(false); %>
<% GraphByFruit[] theObj = (GraphByFruit[])session.getAttribute("GraphData");%>
<% //System.out.print("GraphByFruit[] theObj ="+theObj+"\n");%>
<jsp:useBean id="categoryDataGraph" class="de.laures.cewolf.example.PageViewCountData"/>
<!-- 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.getAttribute("GraphData") %>'/-->
</cewolf:producer>
</cewolf:data>
</cewolf:chart>
<cewolf:img chartid="horizontalBarChart" renderer="cewolf" width="750" height="500">
<cewolf:map tooltipgeneratorid="categoryToolTipGenerator" linkgeneratorid="categoryLink"/>
</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.CategoryDataset;
import org.jfree.data.DefaultCategoryDataset;
import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;
import de.laures.cewolf.CategoryItemLinkGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.chart.tooltips.CategoryToolTipGenerator;
import eplan.graph.business.GraphByFruit;
import javax.servlet.http.*;
/**
* An example data producer.
* @author Guido Laures
* @modified by Zamir A Jalil
*/
public class PageViewCountData implements DatasetProducer,CategoryItemLinkGenerator,CategoryToolTipGenerator,Serializable
{
private static final Log log = LogFactory.getLog(PageViewCountData.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","mon","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("graphSession");
//System.out.print ("HttpSession graphsession ="+graphsession+"\n");
GraphByFruit[] graph = (GraphByFruit[])graphSession.getAttribute("GraphData");;
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().getName() + "hasExpired()");
return (System.currentTimeMillis() - since.getTime()) > 5000;
}
/**
* Returns a unique ID for this DatasetProducer
*/
public String getProducerId() {
return "GraphSessionDataSetProducer";
}
/**
* 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.CategoryToolTipGenerator#generateToolTip(CategoryDataset, int, int)
*/
public String generateToolTip(CategoryDataset arg0, int series, int arg2) {
return arrayOfFruit[series];
}
}
[/code]
by: copyPasteGhostPosted on 2004-05-13 at 19:16:12ID: 11064869
which line does it throw the exception
on.getAttr ibute("Gra phData");;
te("GraphD ata") instanceOf GraphByFruit[]) {
te("GraphD ata") instanceOf GraphByFruit[]) { on.getAttr ibute("Gra phData");
my guess is this one...
>>GraphByFruit[] graph = (GraphByFruit[])graphSessi
there are two semi-colons I don't think that will solve your problem but there should only be one..
if(graphSession.getAttribu
System.out.println("There is a object of type GraphByFruit[] in this session.");
}
see if this line gets printed out. I would add these line just above this one like so...
if(graphSession.getAttribu
System.out.println("There is a object of type GraphByFruit[] in this session.");
}
GraphByFruit[] graph = (GraphByFruit[])graphSessi
Cheers,
Ghost