gwt-RPC问题!使用gwt-RPC的最佳做法是什么?

时间:2010-02-04 10:30:08

标签: java gwt charts gwt-rpc

我想根据使用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);
   }

1 个答案:

答案 0 :(得分:4)

由于GWT RPC是异步的,因此您不知道它是否或何时会成功。与您的代码更相关,因为GWT RPC是一种异步回调机制,它不像线性意义上的同步或程序执行“pContainer.SetaDate(result.aDate.get(1));” 将在“pContainer.aDate.get(0);”之前执行不是在pContainer上设置日期属性并且回调成功,而是将其作为参数传递给生成图表内容的新方法。只需在回调后将所有内容重构为此新方法,并在成功时调用它,并将日期作为arg传递。

相关问题