【问题标题】:Trouble with CellList empty widget and AsyncDataProviderCellList 空小部件和 AsyncDataProvider 出现问题
【发布时间】:2012-05-12 18:50:44
【问题描述】:

我有一个 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 的某些方面。我做错了什么?

【问题讨论】:

    标签: java gwt celllist


    【解决方案1】:

    如果您知道总列表(不仅仅是范围内的列表)为空,那么您可以设置display.setRowCount(0),这样 CellList 将显示“未找到朋友”。

    如果你的服务总是返回整个列表,这可以很容易地完成

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

    【讨论】:

      【解决方案2】:

      将以下行添加到方法中:

      @Override
      public void onSuccess(List<PlayerDataEntity> result) {
         display.setRowData(0, result);
         ((CellList<PlayerDataEntity>) display).redraw();
      }
      

      【讨论】:

      • 有趣的想法,但似乎行不通。 OP 中描述的不良行为仍然存在。
      猜你喜欢
      • 2012-07-31
      • 2023-03-26
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 2018-05-19
      相关资源
      最近更新 更多