2010-02-04 75 views
0

我想根據從數據庫檢索日期使用RPC繪製圖表。gwt-RPC問題!什麼是使用gwt-RPC的最佳實踐?

但每次我都沒有得到結果。我的rpc功能正在工作。

我認爲是過程的順序。下面

是我的課:

public class TrafficPattern_1 extends GChart { 


     TrafficPattern_1() { 

     final DBServiceAsync dbService = GWT 
     .create(DBService.class); 

     dbService.SendData(null, null, 
       new AsyncCallback<Container_TrafficPattern>() { 

        @Override 
        public void onFailure(Throwable caught) { 

        } 

        @Override 
        public void onSuccess(Container_TrafficPattern result) { 
         // TODO Auto-generated method stub 

         pContainer.SetaDate(result.aDate.get(1)); 
        } 
       }); 

     pContainer.aDate.get(0); 
    setChartSize(350, 200); 
     setChartTitle("<h2>Temperature vs Time<h2>"); 
     setPadding("8px"); 
     //setPixelSize(380, 200); 

     getXAxis().setAxisLabel("<small><b><i>Time</i></b></small>"); 
     getXAxis().setHasGridlines(true); 
     getXAxis().setTickCount(6); 
     // Except for "=(Date)", a standard GWT DateTimeFormat string 
     getXAxis().setTickLabelFormat("=(Date)h:mm a"); 

     getYAxis().setAxisLabel("<small><b><i>&deg;C</i></b></small>"); 
     getYAxis().setHasGridlines(true); 
     getYAxis().setTickCount(11); 
     getYAxis().setAxisMin(11); 
     getYAxis().setAxisMax(16); 

     addCurve(); 
     getCurve().setLegendLabel("<i> </i>"); 
     getCurve().getSymbol().setBorderColor("blue"); 
     getCurve().getSymbol().setBackgroundColor("blue"); 
     // getCurve().getSymbol().setFillSpacing(10); 
     // getCurve().getSymbol().setFillThickness(3); 

     getCurve().getSymbol().setSymbolType(SymbolType.LINE); 
     getCurve().getSymbol().setFillThickness(2); 
     getCurve().getSymbol().setFillSpacing(1); 

     for (int i = 0; i < dateSequence.length; i++) 
      // Note that getTime() returns milliseconds since 
      // 1/1/70--required whenever "date cast" tick label 
      // formats (those beginning with "=(Date)") are used. 
      getCurve().addPoint(dateSequence[i].date.getTime(), 
           dateSequence[i].value); 
    } 
+0

添加更多細節。從你的問題來看,人們無法理解實際的問題。什麼不工作?它是否會拋出異常?... – Juri 2010-02-04 10:32:52

+0

當我調用pContainer.aDate.get(0)時,它會提示我一個錯誤。 我把pContainer.aDate.get(0)和另一個RPC函數中的2個斷點放在一個。我發現它運行pContainer.aDate.get(0)1st。 所以我不能得到的數據。 – guaz 2010-02-04 10:35:48

回答

4

由於GWT RPC是異步的,你不知道是否或何時會取得成功。由於GWT RPC是一種異步回調機制,因此它與線程意義上的同步或過程執行不同,即「pContainer.SetaDate(result.aDate.get(1));」 將在「pContainer.aDate.get(0);」之前執行而不是在pContainer上設置日期屬性並回調成功,將其作爲參數傳遞給生成圖表內容的新方法。只需在回調之後重新構造這個新方法,並在成功時調用它,並將日期作爲參數傳遞給它。