[英]gwt-RPC problem! what is the best practice on using 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>°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);
}
由于GWT RPC是异步的,因此您不知道它是否或何时成功。 而且与您的代码更相关,因为GWT RPC是一种异步回调机制,从线性意义上说,“ pContainer.SetaDate(result.aDate.get(1));”不像同步或过程执行那样。 将在“ pContainer.aDate.get(0);”之前执行 无需在pContainer上设置成功回调成功的date属性,而是将其作为参数传递给生成图表内容的新方法。 只需将回调后的所有内容重构为此新方法,并在成功时调用它,并将日期作为arg传递即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.