[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

ClassCastException error in reading session.

Asked by zamirjalil in Java Server Pages (JSP)

Tags: cewolf, classcastexception

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]
[+][-]05/13/04 07:16 PM, ID: 11064869Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Java Server Pages (JSP)
Tags: cewolf, classcastexception
Sign Up Now!
Solution Provided By: copyPasteGhost
Participating Experts: 2
Solution Grade: A
 
[+][-]05/13/04 07:23 PM, ID: 11064947Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/14/04 03:36 AM, ID: 11066840Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07/08/04 05:49 AM, ID: 11501385Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07/12/04 05:18 PM, ID: 11534872Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07/12/04 06:05 PM, ID: 11535115Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92