javagwtdatatabledataprovidersimplepager

GWT DataTable with SimplePager freezed after DataProvider modification


I've got a strange problem with SimplePager of DataTable in GWT 2.7.0 I created a DataTable in the View in this way:

private void initCellTable() {     
    pecMessageCellTable = new CellTable<>();
    dataProvider = new ListDataProvider<>();
    dataProvider.addDataDisplay(pecMessageCellTable);
    pecMessageCellTable.setPageSize(DEFAULT_PAGE_SIZE);
    pecMessageCellTable.setVisibleRange(0,DEFAULT_PAGE_SIZE);
    pecMessageCellTable.setWidth("100%", true);
    pecMessageCellTable.setAutoHeaderRefreshDisabled(true);
    pecMessageCellTable.setAutoFooterRefreshDisabled(true);

    pecMessageCellTable.setEmptyTableWidget(new NoResults());
   //sort handler
    ColumnSortEvent.ListHandler<PecMessage> sortHandler = new ColumnSortEvent.ListHandler<>(dataProvider.getList());
    pecMessageCellTable.addColumnSortHandler(sortHandler);


    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(SimplePager.TextLocation.CENTER, pagerResources, false, 0,  true);
    pager.setDisplay(pecMessageCellTable);

    pager.setVisible(false);

    //from
    TextColumn<PecMessage> fromColumn = new TextColumn<PecMessage>() {
        @Override
        public String getValue(PecMessage message) {
            return message.getFrom().iterator().next();
        }
    };

    fromColumn.setSortable(true);
    pecMessageCellTable.addColumn(fromColumn, "Mittente");
    pecMessageCellTable.setColumnWidth(fromColumn, 18, Unit.PCT);

    //subject
    TextColumn<PecMessage> subjColumn = new TextColumn<PecMessage>() {
        @Override
        public String getValue(PecMessage message) {
            return message.getSubject();
        }
    };      

    subjColumn.setSortable(true);
    pecMessageCellTable.addColumn(subjColumn, "Oggetto");

    //received date
    TextColumn<PecMessage> sentDateColumn = new TextColumn<PecMessage>() {
        @Override
        public String getValue(PecMessage message) {
            return DateTimeFormat.getFormat("dd/MM/yy hh:mm:ss").format(message.getReceived());
        }
    };

    sentDateColumn.setSortable(true);
    pecMessageCellTable.addColumn(sentDateColumn, "Data Ricezione");
    pecMessageCellTable.setColumnWidth(sentDateColumn, 12, Unit.PCT);

    ImageCell imageCell=new ImageCell();
    Column<PecMessage,String> iconColumn = new Column<PecMessage, String>(imageCell){

        @Override
        public String getValue(PecMessage object) {
            return object.getImageUrl(object);
        }

    };


    pecMessageCellTable.addColumn(iconColumn,"Lock");
    pecMessageCellTable.setColumnWidth(iconColumn, 46, Unit.PX);


    //delete Message
    ButtonCell buttonCell = new ButtonCell(ButtonType.DANGER, IconType.TRASH);
    Column<PecMessage, String> deleteBtn = new Column<PecMessage, String>(buttonCell) {
        @Override
        public String getValue(PecMessage object) {
            return "Elimina";
        }
    };

    pecMessageCellTable.addColumn(deleteBtn, "Elimina");
    pecMessageCellTable.setColumnWidth(deleteBtn, 9, Unit.PCT);   
    pecMessageCellTable.setVisible(false);

}

I populated the data provider later in the code acting a little bit on pager:

public void setEmails(Map<String,PecMessage> emails) {
        try {
            this.emails = emails;
            if(pager.isVisible())
                pager.startLoading();

            if(emails!=null) {
                pecMessageCellTable.setVisibleRangeAndClearData(new Range(0, DEFAULT_PAGE_SIZE), true);
                List<PecMessage> list=new ArrayList<PecMessage>(emails.values());

                dataProvider.setList(list);

                pecMessageCellTable.setRowCount(list.size());

            }
            if(!pecMessageCellTable.isVisible())
                pecMessageCellTable.setVisible(true);


            loginFildSet.setVisible(false);
            loginBtn.setVisible(false);
            logoutBtn.setVisible(true);
            refreshBtn.setVisible(true);

            if(!pager.isVisible())
                pager.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

I've also added some handlers for specific click events for the rows of the table. Handling events, I need to update some rows and I can do it in this way:

public void updateLock(PecMessage message){
        int i=dataProvider.getList().indexOf(message);
        message.setLockedState(0);
        dataProvider.getList().set(i, message);
        dataProvider.flush();
        dataProvider.refresh();
}

When user fires events and modify some elements of the datatable I always call dataProvider.flush() and dataProvider.refresh() but sometimes, the DataTable pagination seems not to work anymore, the SimplePager changes its range values but does not change table pages, the table is freezed and the user is not able to change page anymore. It happen randomly so it's hard to fix.

Some suggestion on this strange behaviour?

UPDATE 1: I realize that the error sould be in setEmails() method because the problem happens only if I modify entirely the list in the dataProvider, hope this could restrict investigation area.


Solution

  • I've figured out the problem. I analyzed better the browser console and I found a specific error related to a java classes:

    Mon Feb 13 14:59:29 GMT+100 2017 com.google.gwt.logging.client.LogConfiguration
    SEVERE: (TypeError) : Cannot read property 'eQ' of nullcom.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'eQ' of null
        at Unknown.ER(Exceptions.java:36)
        at Unknown.Nk(PecMessage.java:322)
        at Unknown.X(Object.java:66)
        at Unknown.VY(HasDataPresenter.java:1017)
        at Unknown.aZ(HasDataPresenter.java:1139)
        at Unknown.qZ(HasDataPresenter.java:984)
        at Unknown.jt(SchedulerImpl.java:185)
        at Unknown._s(SchedulerImpl.java:279)
        at Unknown.Qs(Impl.java:323)
        at Unknown.Ps(Impl.java:314)
        at Unknown.anonymous(Impl.java:72)
    

    At PecMessage.java:322 I found that equals() method was not up to date and did not control null values. Some new attributes were added to the object, and other attributes were modified, so I updated equals() and hashCode() methods and now the CellTable seems to work properly.