GWT: How to programmatically reload CellBrowser?

后端 未结 4 2074
旧时难觅i
旧时难觅i 2021-02-08 21:31

I\'m using GWT 2.1\'s CellBrowser with a custom TreeViewModel. The TreeViewModel in turn uses an AsyncDataProvider to fetch data dynamically. This all

4条回答
  •  清歌不尽
    2021-02-08 21:35

    It looks like a lot of people are having this same issue. Here's how I handled refreshing the data from an AsyncDataProvider.

    First, create an interface that adds the ability to refresh data provider by wrapping the AsyncDataProvider's protected onRangeChanged method. For example...

    HasRefresh.java

    public interface HasRefresh>{
      /**
       * Called when a display wants to refresh 
       *
       * @param display the display to refresh
       */
       void refresh(HasData display);
    
    }
    

    Then the CellTable needing to be refreshed can then call into it through an Activity or however your controller logic is setup.

    /**
    * A custom {@link AsyncDataProvider}.
    */
    public class MyAsyncDataProvider extends
                AsyncDataProvider implements HasRefresh {
    
                public void refresh(Entity display){
    
                      onRangeChanged(display);
                 }
    
                 /**
             * {@link #onRangeChanged(HasData)} is called when the table requests a
             * new range of data. You can push data back to the displays using
             * {@link #updateRowData(int, List)}.
             */
            @Override
            protected void onRangeChanged(
                    HasData display) {
                currentRange = display.getVisibleRange();
                final int start = currentRange.getStart();
    
                dataServiceQuery = context.getEntities();
    
                dataServiceQuery
                        .execute(new DataServiceQueryHandler() {
    
                            @Override
                            public void onQueryResponse(
                                    DataServiceQueryResponse response) {
    
    
                                updateRowCount(response.getCount(), true);
                                updateRowData(start, response.getEntities());
    
                            }
                        });
    
            }// end onRangeChanged()
    
        }// end MyAsyncDataProvider class
    

提交回复
热议问题