java - CellList 空小部件和 AsyncDataProvider 出现问题

标签 java gwt celllist

我有一个 CellList,我正在使用 AsyncDataProvider 填充它:

  @UiField(provided = true)
  CellList<PlayerDataEntity> friendCellList;


  @Inject
  FriendListViewImpl(FriendListController controller) {
    friendCellList = new CellList<PlayerDataEntity>(new PlayerCell());

    initWidget(uiBinder.createAndBindUi(this));

    // if we don't set the row data to empty before trying to get the real data,
    // the empty list widget will never appear. But if we do set this, 
    // then the real data won't show up. 
    friendCellList.setRowData(Lists.<PlayerDataEntity>newArrayList());

      new AsyncDataProvider<PlayerDataEntity>() {
        @Override
        protected void onRangeChanged(final HasData<PlayerDataEntity> display) {
          rpcService.getPlayers(new AsyncCallback<List<PlayerDataEntity>>() {
              @Override
              public void onSuccess(List<PlayerDataEntity> result) {
                 display.setRowData(0, result);
              }
            });
      }
    }.addDataDisplay(friendCellList);

    friendCellList.setEmptyListWidget(new Label("No friends found"));
  }

如果我最初没有将行数据设置为空列表,那么当 RPC 服务返回空列表时,空列表小部件将不会显示。但是,如果我最初将行数据设置为空列表,并且 RPC 返回非空列表,则该数据将不会显示在小部件中。

我一定是误解了 CellList API 的某些方面。我做错了什么?

最佳答案

如果你知道总列表(不仅仅是范围内的列表)为空,那么你可以设置display.setRowCount(0),这样CellList就会显示“Nofriendsfound” ”。

如果您的服务始终返回整个列表,则可以轻松完成,例如

public void onSuccess(List<PlayerDataEntity> result) {
  display.setRowCount(result.size());
  display.setRowData(0, result);
}

关于java - CellList 空小部件和 AsyncDataProvider 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10566483/

相关文章:

java - 将点击处理程序添加到 GWT 中的 Horizo​​ntalPanel

java - 单击时如何复制 SmartGWT 悬停文本的外观/功能

mgwt - 如何删除 MGWT CellList 中的 > 符号

java - 在 tomcat 8 的共享文件夹中添加属性文件并在 Spring MVC Web 应用程序中使用它

java - 使用 GWT 监控数据库

Java归并排序, "merge"这一步应该用队列还是数组来完成?

mgwt - 在 MGWT 中为每个 celllist 单元格添加文本和图像

java - 使用枚举存储和获取静态值

java - Java 8 `Stream` 可以在您不要求的情况下并行吗?