2010-02-04 72 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上设置日期属性并回调成功,将其作为参数传递给生成图表内容的新方法。只需在回调之后重新构造这个新方法,并在成功时调用它,并将日期作为参数传递给它。