How can i pass an array through a runnable interface ?

19 views
Skip to first unread message

Laurent Pierre

unread,
Oct 27, 2011, 5:12:58 PM10/27/11
to Google Web Toolkit

Hi Chaps,

I'm doing a succesful call to a servlet which is returning a String array.
Array's datas should be used to display a pie chart.

What is the best way to pass these datas to createtable() in order to fill the data table  ?

Did tried a couple of ideas but i had some error messages like "referring-to-a-non-final-variable-data-inside-an-inner-class" and others .
Can someone help me fix this because i'm beating around the bush ?

Regards,

Pierre
---------------------------------------------------------------

Service.callD(F,
      new AsyncCallback() {
       public void onFailure(Throwable caught) {
        dialogBox
          .setText("Remote Procedure Call - Failure");
        serverResponseLabel
          .addStyleName("serverResponseLabelError");
        serverResponseLabel.setHTML(SERVER_ERROR);
        dialogBox.center();
        closeButton.setFocus(true);
       }

       @Override
       public void onSuccess(String[][] result) {
        
          Runnable onLoadCallback = new Runnable() {
              public void run() {

              
                PieChart pie = new PieChart(createTable(), createOptions());

                pie.addSelectHandler(createSelectHandler(pie));
                horizontalPanel_2.add(pie);
              }
            };
            VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
        
          }
  ---------------------------------------------------------------       
          
 private AbstractDataTable createTable() {
         
         
           DataTable data = DataTable.create();
           data.addColumn(ColumnType.STRING, "Libelle");
           data.addColumn(ColumnType.NUMBER, "Nombre");
           data.addRows(4);
           data.setValue(0, 0, "Defaut 1");
           data.setValue(0, 1, 14);
           data.setValue(1, 0, "Defaut 2");
           data.setValue(1, 1, 10);
           data.setValue(2, 0, "Defaut 3");
           data.setValue(2, 1, 25);
           data.setValue(3, 0, "Defaut 4");
           data.setValue(3, 1, 2);
          
           return data;
         }
---------------------------------------------------------------

Jens

unread,
Oct 28, 2011, 4:24:32 AM10/28/11
to google-we...@googlegroups.com, Laurent Pierre
Make your result final, e.g. onSuccess(final String[][] result). You can now use it inside the Runnable anonymous class.

Different way would be to create a class that implements Runnable. The class could have a constructor that takes the string array as argument, stores it in a field and then use it in its run() method.
Reply all
Reply to author
Forward
0 new messages