0

我似乎对 GWT 异步调用的工作方式和/或小部件在收到回调后如何更新存在一些根本性的误解。

我已经创建了两个接口以及实现,它们似乎正在相互通信。我根据在使用 eclipse 调试器单步执行时观察到的合理外观数据做出此声明:result下面的 onSuccess 方法中的变量包含我期望的内容,并且我尝试填充的网格最终被results退出时的数据填充从循环。但是,当onSuccess调用返回时,我的 GUI 中不会根据uhpScrollPanel.setWidget(uhpGrid)调用显示任何网格,并且不会引发任何类型的异常。

我一定是忽略了一些明显的东西,有没有人知道在哪里看?

    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++;
            }
        }

    });
4

2 回答 2

0

您的onSuccess()方法定义不正确,作为它接收的参数Object,您必须在之后对其进行向下转换。

意思是,签名应该是:

public void onSuccess(Object result)

之后,您可以像这样显式地向下转换您知道已返回的对象:

List<UpdateHistoryEntryBean> resultList = (List<UpdateHistoryEntryBean>) result;
于 2009-02-11T21:07:35.540 回答
0

事实证明,快速修复是将网格添加到 VerticalPanel 而不是 ScrollPanel。现在的问题变成了 - 为什么这很重要,我们如何解决这个困境?

于 2009-02-11T21:09:28.750 回答