Question

I try using Google Chart to display the trendlines, based on some datas generated from the .java files. My basic idea is to create a DataTable in java file, and then I pass this DataTable to web pages by JSF.

Here are part of my codes:

public void resolveEvolution() {
        this.evolution = new ArrayList<Long>();
        this.evolutionTime = new ArrayList<String>();
        Calendar first = Calendar.getInstance();
        first.setTime(this.start);
        first.set(Calendar.DAY_OF_MONTH, 1);
        Calendar last = Calendar.getInstance();
        last.setTime(this.end);

        int i = 0;

        this.dt = DataTable.create();
        dt.addColumn(ColumnType.NUMBER, "Time");
        dt.addColumn(ColumnType.NUMBER, "Utilisation");
        dt.addRow();
        while (first.before(last)) {
            Calendar endMonth = Calendar.getInstance();
            endMonth.setTime(first.getTime());
            endMonth.add(Calendar.MONTH, 1);
            endMonth.add(Calendar.DAY_OF_MONTH, -1);

            this.evolution
                    .add(actionQueries.countByComponent(this.selectedComponent,
                            first.getTime(), endMonth.getTime()));
            this.evolutionTime.add(first.get(Calendar.MONTH) + "/"
                    + first.get(Calendar.YEAR));
            dt.addRow();
            dt.setValue(i, 0, i);
            dt.setValue(i, 1,
                    actionQueries.countByComponent(this.selectedComponent,
                            first.getTime(), endMonth.getTime()));
            i++;
            first.add(Calendar.MONTH, 1);
        }
    }

    public DataTable getDt() {
        System.out.println(this.dt);
        return this.dt;
    }

And in my .xhtml file it's like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
    <head>    
<script type="text/javascript" src="https://www.google.com/jsapi"></script>    
<script type="text/javascript">      
    google.load("visualization", "1", {packages:["corechart"]});     
    google.setOnLoadCallback(drawChart);      
    function drawChart() {        
        var data = new google.visualization.DataTable();
        data = "#{globalComponentsManager.dt}";
        var options = {         
            title: 'Test',
                           trendlines: { 0: {} }

        };    
        var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));

        chart.draw(data, options);      
    }    
    </script> 
 </head>  
 <body>   
      <div id="chart_div" style="width: 900px; height: 500px;"></div> 
 </body> 

</html>

However, when I execute this application in Tomcat, it tells me:

GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.apache.myfaces.webapp.StartupServletContextListener
java.lang.NoClassDefFoundError: com/google/gwt/core/client/JavaScriptObject

What's the problem? Thanks in adavance.

Was it helpful?

Solution

I think you are using the wrong libraries (see the java.lang.NoClassDefFoundError: com/google/gwt/core/client/JavaScriptObject error).

I guess the resolveEvolution() method runs on the server.
The DataTable you try to use is used for GWT applications and not for the backend code (JSF).
Instead of the gwt-google-apis you should use the DataTable that is part of the Data Soruce Java library

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top