我似乎正在遭受一些基本的誤解,認爲GWT異步調用的工作方式和/或在收到回調後如何更新小部件。基礎GWT異步調用誤解
我創建了兩個接口以及實現,他們似乎在互相通信。我在使用eclipse調試器的同時觀察到合理的觀察數據來做出此聲明:以下onSuccess方法中的result
變量包含我期望的數據,並且我試圖填充的網格最終填充了來自results
的數據在退出循環時。但是,當onSuccess
調用返回時,根據uhpScrollPanel.setWidget(uhpGrid)
調用,我的GUI中不會顯示任何網格,也不會拋出任何異常。
我一定是在眺望一些明顯的東西,有沒有人有什麼想法在哪裏看?
final ScrollPanel uhpScrollPanel = new ScrollPanel();
uhpVert.add(uhpScrollPanel);
uhpScrollPanel.setSize("100%", "100%");
//build and populate grid
UpdateHistoryServiceAsync uhpService = UpdateHistoryService.Util.getInstance();
uhpService.getUpdateHistory(new AsyncCallback<List<UpdateHistoryEntryBean>>() {
public void onFailure(Throwable caught) {
System.out.println("OnFailure");
caught.printStackTrace();
final Label uhpErrorLabel = new Label("Server Unable to Grab History...");
uhpScrollPanel.setWidget(uhpErrorLabel);
uhpErrorLabel.setSize("100%", "100%");
}
public void onSuccess(List<UpdateHistoryEntryBean> result) {
int length = result.size();
final Grid uhpGrid = new Grid();
uhpScrollPanel.setWidget(uhpGrid);
uhpGrid.setBorderWidth(1);
uhpGrid.setSize("100%", "100%");
uhpGrid.resize(length, 3);
int i = 0;
for (UpdateHistoryEntryBean entry : result) {
uhpGrid.setText(i, 0, String.valueOf(entry.getSourceId()));
uhpGrid.setText(i, 1, entry.getTitle());
uhpGrid.setText(i, 2, entry.getBody());
i++;
}
}
});
Yuval,你確定?我正在使用GWT 1.5和Java 1.5 - 全面支持泛型。該方法sig是通過工具支持生成的(GWTDesigner是具體的...)。在任何情況下,預期的數據都在我的結果變量中出現,所以我認爲 這不是問題。謝謝你嘗試! – 2009-02-11 21:14:15
在GWT 1.5+你可以做到這一點,所以它沒有錯 – rustyshelf 2009-02-12 00:30:49