wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes cewolf - passing data to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "cewolf - passing data to jsp" Watch "cewolf - passing data to jsp" New topic
Author

cewolf - passing data to jsp

Surya Ram
Greenhorn

Joined: Aug 09, 2004
Posts: 7
Hi,
I am using the cewolf example code(PageViewCountData class) to create a chart.
The chart comes up good in a jsp.
I am having problem to pass a value(pageCount in the below code) back to the same jsp but show it outside of the chart.

Any help is greatly appreciated. Thanks!

Here is the java code -
public class PageViewCountData implements DatasetProducer, CategoryToolTipGenerator, CategoryItemLinkGenerator, Serializable {

private static final Log log = LogFactory.getLog(PageViewCountData.class);

/**
* Produces some random data.
*/
public Object produceDataset(Map params) throws DatasetProduceException {

log.debug("producing data.");
DefaultCategoryDataset dataset = new DefaultCategoryDataset(){

/**
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
super.finalize();

log.debug(this +" finalized.");
}
};
int pageCount=5;

for (int series = 0; series < vec3.size(); series ++) {

for (int i = 0; i < 30; i++) {
dataset.addValue(Integer.parseInt(vec2.elementAt(i).toString()), vec3.elementAt(series).toString(), vec1.elementAt(i).toString().substring(4,9));
// System.out.println("***"+vec2.elementAt(i).toString()+"***"+vec3.elementAt(series).toString()+"***"+vec1.elementAt(i));
}
}
return dataset;
}


//Here is the jsp
<jsp:useBean id="pageViews" class="de.laures.cewolf.example.PageViewCountData"/>
<cewolf:chart id="line" title="Stats" type="line" xaxislabel="Dates" yaxislabel="Stats">
<cewolf:data>
<cewolf:producer id="pageViews"/>
</cewolf:data>
</cewolf:chart>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41604
    
  55
The produceDataset method is called when the image is generated - which is long after the JSP has run. So whatever value you have in that method can't be used in the JSP.

But since the value doesn't seem to change, maybe the PageViewCountData class can set it as a request attribute - which would make it accessible to the JSP.


Ping & DNS - my free Android networking tools app
Surya Ram
Greenhorn

Joined: Aug 09, 2004
Posts: 7
Thank You! for the reply.

Actually I am accessing the DB to get the value of pageCount (so this value is based on the query to db)in produceDataset method of PageViewCountData class.

Is there a way to pass it to the same jsp but show it outside of the chart.


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41604
    
  55
Since the code you posted doesn't seem to use pageCount, I'd move the logic to retrieve the value from the DB to whichever servlet handles this JSP page - then you can set it as a request attribute.
 
jQuery in Action, 2nd edition
 
subject: cewolf - passing data to jsp