So you can see, the "<%!" block at the top declare your class, and then you use an instance of it in the "<%" block :-)
Hope this makes sense (and works) ;-)
Hee hee
Tim
Main Topics
Browse All TopicsHello experts out there,
I try to generate line graph based on cewolf open source graph software.
What I want to do is I want to get some data from 'GraphByFruit' class that passed in object of array. This object is stored in a session attribute "GraphData".
My below code produce error msg : "local variable request is accessed from within inner class; needs to be declared final"
How should I get the value from "GraphByFruits" class??
pls help...
my code in jsp:
DatasetProducer categoryData = new DatasetProducer() {
HttpSession logSession = request.getSession(false);
public Object produceDataset(Map params) {
GraphByFruit[] graph = (GraphByFruit[])session.ge
String state = "";
String fruit = "";
float[] qty = null;
final String[] arrayOfFruit = new String[graph.length];
System.out.print("arrayOfF
final String[] categories= { "a", "s", "d", "f", "g", "h", "j", "k", "r"};
for (int i=0; i < graph.length; i++) {
state=graph[i].getStateID(
qty = graph[i].getProdQty();
fruit = ""+graph[i].getFruitID();
if (i<graph.length-1) fruit = fruit+",";
arrayOfFruit [i] = fruit;
}
//final String[] categories = { "apples", "pies", "bananas", "oranges" };
//final String[] seriesNames = { "Peter", "Helga", "Franz", "Olga" };
final Integer[][] startValues = new Integer[arrayOfFruit.lengt
final Integer[][] endValues = new Integer[arrayOfFruit.lengt
for (int series = 0; series < arrayOfFruit.length; series++) {
for (int i = 0; i < categories.length; i++) {
int y =0;
startValues[series][i] = new Integer(y);
endValues[series][i] = new Integer(y + (int) (Math.random() * 10));
}
}
DefaultIntervalCategoryDat
new DefaultIntervalCategoryDat
return ds;
}
public String getProducerId() {
return "CategoryDataProducer";
}
public boolean hasExpired(Map params, Date since) {
return false;
}
};
pageContext.setAttribute("
%>
<html>
<head>
<link href="cewolf.css" rel="stylesheet" type="text/css"></head>
<BODY bgcolor="#DDE8F2">
<H1>Cewolf Chart Set</H1>
<p>
<cewolf:chart id="lineChart" title="LineChart" type="line" xaxislabel="Fruit" yaxislabel="favorite">
<cewolf:data>
<cewolf:producer id="categoryData" />
</cewolf:data>
</cewolf:chart>
<cewolf:img chartid="lineChart" renderer="cewolf" width="300" height="300"/>
</body>
</html>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi TimYates...
I follow you way but it produce this error.. pls consult...
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] /usr/local/tomcat4/work/St
[javac] pageContext.setAttribute("
[javac] ^
[javac] 1 error
ok... as you said I call the intance of data in different block.. then the error resolve... BUT...
this error appear:
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] /usr/local/tomcat4/work/St
[javac] symbol : variable session
[javac] location: class org.apache.jsp.graph_jsp.C
[javac] GraphByFruit[] graph = (GraphByFruit[])session.ge
[javac] ^
[javac] /usr/local/tomcat4/work/St
[javac] found : int
[javac] required: java.lang.String
[javac] state=graph[i].getStateID(
[javac] ^
pls help...
sorry TimYates... this is should be error before previous post... sorry again..
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] /usr/local/tomcat4/work/St
[javac] class CatData extends DatasetProducer
[javac] ^
ohhh no... then come another error..
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] /usr/local/tomcat4/work/St
[javac] symbol : variable session
[javac] location: class org.apache.jsp.graph_jsp.C
[javac] GraphByFruit[] graph = (GraphByFruit[])session.ge
pls help ....
Note: Declaring a class inside a JSP and then putting in the session is a REALLY BAD IDEA. Especially when developing, you will find that if you put an instance in the session, and then change the JSP, you will get a ClassCastException when you get the instance back out again.
The latest problem you are encountering is because you mix and match use of logSession and session.
I think you probably want to use logSession. But rememeber, you are now putting an object into a session that contains a reference to the session itself. This is horrible.
That will get it to compile, yes. From your original question, you could also just have changed:
DatasetProducer categoryData = new DatasetProducer() {
HttpSession logSession = request.getSession(false);
public Object produceDataset(Map params) {
GraphByFruit[] graph = (GraphByFruit[])session.ge
To:
final logSession = request.getSession();
DatasetProducer categoryData = new DatasetProducer() {
public Object produceDataset(Map params) {
GraphByFruit[] graph = (GraphByFruit[])logSession
That will get it to compile, yes. From your original question, you could also just have changed:
DatasetProducer categoryData = new DatasetProducer() {
HttpSession logSession = request.getSession(false);
public Object produceDataset(Map params) {
GraphByFruit[] graph = (GraphByFruit[])session.ge
To:
final HttpSession logSession = request.getSession();
DatasetProducer categoryData = new DatasetProducer() {
public Object produceDataset(Map params) {
GraphByFruit[] graph = (GraphByFruit[])logSession
guys.. by following Tim ways, I am able to call data from GraphByFruit object... but I am not able to implement generateLink and tooltip tag in categoryLink attribute dan catTG.. pls help
below is the update code
<%@page contentType="text/html"%>
<%@taglib uri='../../WEB-INF/cewolf.
<%@ taglib uri="/WEB-INF/struts-html.
<%@ taglib uri="/WEB-INF/struts-bean.
<%@ taglib uri="/WEB-INF/struts-logic
<%@page import="eplan.graph.busine
<%@page import="java.util.*"%>
<%@page import="de.laures.cewolf.*
<%@page import="org.jfree.data.*"%
<%@page import="org.jfree.data.tim
<%@page import="org.jfree.chart.to
<%@page import="org.jfree.chart.*"
<%@page import="org.jfree.chart.pl
<%@page import="java.lang.*"%>
<%@page import="org.apache.commons
<%@page import="org.apache.commons
<%@page import="org.jfree.chart.re
<%!
class CatData implements DatasetProducer
{
GraphByFruit[] graph;
String[] arrayOfFruit;
public CatData( GraphByFruit[] _graph)
{
graph=_graph ;
String temp[] = new String[graph.length];
arrayOfFruit=temp;
}
public Object produceDataset(Map params)
{
int month = 0;
String state = "";
String fruit = "";
float[] qty = null;
double lastY=0;
final String[] arrayOfFruit = new String[graph.length];
final String[] categories= { "Jan", "Feb", "Mac", "Apr", "May", "Jun", "Jul", "Aug", "Sep","Oct","Nov","Dec"};
DefaultCategoryDataset dataset = new DefaultCategoryDataset(){
/**
* @see java.lang.Object#finalize(
*/
protected void finalize() throws Throwable {
super.finalize();
}
};
//put result into array
String fruitName="";
for (int series = 0; series < arrayOfFruit.length; series ++) {
Integer fruitID = new Integer(graph[series].getF
arrayOfFruit[series] = fruitID.toString();
System.out.print("\narrayO
state= ""+graph[series].getStateI
qty = graph[series].getProdQty()
System.out.print("\nCatego
for (int i = 0; i < categories.length; i++) {
final double y = qty[i];
//System.out.print("\nValu
//System.out.print("arrayO
//System.out.print("catego
lastY = y;
dataset.addValue((double)y
}
}
return dataset;
}
public String getProducerId() {
return "CategoryDataProducer";
};
public boolean hasExpired(Map params, Date since) {
return false;
};
CategoryItemLinkGenerator categoryLink = new CategoryItemLinkGenerator(
public String generateLink(Object dataset, int series, Object category) {
return "test";//arrayOfFruit[seri
}
};
CategoryToolTipGenerator catTG = new CategoryToolTipGenerator()
public String generateToolTip(CategoryDa
return String.valueOf(dataset.get
}
};
%>
} // end class
<%
HttpSession getSession=request.getSess
GraphByFruit[] getGraph = (GraphByFruit[]) session.getAttribute("Grap
CatData data = new CatData( getGraph ) ;
pageContext.setAttribute("
pageContext.setAttribute("
pageContext.setAttribute("
%>
<html:html locale="true">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<cewolf:chart id="lineChart" title="LineChart" type="line" xaxislabel="Month"
yaxislabel="Total">
<cewolf:data>
<cewolf:producer id="categoryData" />
</cewolf:data>
</cewolf:chart>
<cewolf:img chartid="lineChart" renderer="cewolf" width="800" height="550"/>
<cewolf:map tooltipgeneratorid="catego
</cewolf:img>
</div>
</body>
</html:html>
Error generated :
java.lang.NullPointerExcep
at org.apache.jsp.graph_jsp$C
at org.apache.jsp.graph_jsp._
at org.apache.jasper.runtime.
at javax.servlet.http.HttpSer
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
---
Things that could be null:
getGraph from:
HttpSession getSession=request.getSess
GraphByFruit[] getGraph = (GraphByFruit[]) session.getAttribute("Grap
CatData data = new CatData( getGraph ) ;
this would cause a NullPointerException in the CatData constructor at the line:
String temp[] = new String[graph.length];
Why bother setting three attributes in the page when they are all contained within your CatData object anyway?
pageContext.setAttribute("
pageContext.setAttribute("
pageContext.setAttribute("
Why is your closing bracket for your inner class OUTSIDE of the <%! %> markers?
%>
} // end class
yes..now it is working.. just a silly mistake :))
just change
from :
<cewolf:img chartid="lineChart" renderer="cewolf" width="800" height="550"/>
<cewolf:map tooltipgeneratorid="catego
</cewolf:img>
to:
<cewolf:img chartid="lineChart" renderer="cewolf" width="800" height="550">
<cewolf:map tooltipgeneratorid="catego
</cewolf:img>
Thanks a lot to TimYates..
Business Accounts
Answer for Membership
by: TimYatesPosted on 2004-04-26 at 00:17:29ID: 10916072
It's the line:
tAttribute ("GraphDat a"); ruit ="+arrayOfFruit.length+"\n ");
);
h][categor ies.length ]; h][categor ies.length ]; aset ds = aset(serie sNames, categories, startValues, endValues);
categoryDa ta", data );
HttpSession logSession = request.getSession(false);
that will be causing the problems...basically, with anonymous inner classes, you can only access variables from outside the class declaration (but local to a method) if they are declared final.
As you cannot control the modifiers for "request" in this method, you will have to declare your own class like so:
<%!
class CatData extends DatasetProducer
{
HttpSession logSession ;
public CatData( HttpSession session )
{
logSession = session ;
}
public Object produceDataset(Map params)
{
GraphByFruit[] graph = (GraphByFruit[])session.ge
String state = "";
String fruit = "";
float[] qty = null;
final String[] arrayOfFruit = new String[graph.length];
System.out.print("arrayOfF
final String[] categories= { "a", "s", "d", "f", "g", "h", "j", "k", "r"};
for (int i=0; i < graph.length; i++) {
state=graph[i].getStateID(
qty = graph[i].getProdQty();
fruit = ""+graph[i].getFruitID();
if (i<graph.length-1) fruit = fruit+",";
arrayOfFruit [i] = fruit;
}
//final String[] categories = { "apples", "pies", "bananas", "oranges" };
//final String[] seriesNames = { "Peter", "Helga", "Franz", "Olga" };
final Integer[][] startValues = new Integer[arrayOfFruit.lengt
final Integer[][] endValues = new Integer[arrayOfFruit.lengt
for (int series = 0; series < arrayOfFruit.length; series++) {
for (int i = 0; i < categories.length; i++) {
int y =0;
startValues[series][i] = new Integer(y);
endValues[series][i] = new Integer(y + (int) (Math.random() * 10));
}
}
DefaultIntervalCategoryDat
new DefaultIntervalCategoryDat
return ds;
}
public String getProducerId() {
return "CategoryDataProducer";
}
public boolean hasExpired(Map params, Date since) {
return false;
}
}
%>
<%
CatData data = new CatData( session ) ;
pageContext.setAttribute("
%>