2014-01-26 9 views
0

이 예제에서 설명한대로 AsyncDataProvider를 사용하여 CellTable을 생성하고 있습니다. http://www.mytechtip.com/2010/11/gwt-celltable-example-using_8168.htmlasyncdata 공급자를 사용하는 CellTable

여기서 언급 한대로 원격 서비스를 호출하여 레코드를 가져 오는 두 번째 방법을 사용하고 있습니다.

// Associate an async data provider to the table 
AsyncDataProvider<Contact> provider = new AsyncDataProvider<Contact>() { 
    @Override 
    protected void onRangeChanged(HasData<Contact> display) { 
    final int start = display.getVisibleRange().getStart(); 
    int length = display.getVisibleRange().getLength(); 
    AsyncCallback<List<Contact>> callback = new AsyncCallback<List<Contact>>() { 
     @Override 
     public void onFailure(Throwable caught) { 
     Window.alert(caught.getMessage()); 
     } 
     @Override 
     public void onSuccess(List<Contact> result) { 
     updateRowData(start, result); 
     } 
    }; 
    // The remote service that should be implemented 
    remoteService.fetchPage(start, length, callback); 
    } 
} 

내 remoteService.fetchPage() 메서드에서 1000 레코드가 반환되며 페이지에 50 레코드를 표시하는 방법이 확실하지 않습니다.

답변

0

중간 버퍼를 만들어 끝에 도달 할 때까지 결과를 50 개씩 반환 할 수 있습니다. 그때 만 다음 요청을 위해 서버로 돌아옵니다.

new AsyncDataProvider<Contact>() { 
    List<Contact> buffer; 
    int currentLastIndex; 

    @Override 
    protected void onRangeChanged(HasData<Contact> display) { 
    if(currentLastIndex % 1000 != 0) { 
     //return 50 contacts from buffer 
     updateRowData(currentLastIndex, getResultFromBuffer()); 
    } else { 
    AsyncCallback<List<Contact>> callback = new AsyncCallback<List<Contact>>() { 
     @Override 
     public void onFailure(Throwable caught) { 
     Window.alert(caught.getMessage()); 
     } 
     @Override 
     public void onSuccess(List<Contact> result) { 
     buffer.addAll(result); 
     updateRowData(currentLastIndex, getResultFromBuffer()); 
     } 
    }; 
    // The remote service that should be implemented 
    } 

List<Contact> getResultFromBuffer() { 
    //I didn't check the javadoc for sublist, but somehow this way 
    return buffer.sublist(currentLastIndex, currentLastIndex +50); 
} 
    }