2012-05-14 15 views
2
  1. 我想创建一个CellTable。但是celltable的列应该基于服务器的响应。我以List的形式获得服务器响应。如何根据服务器的响应创建CellTable

    No of Columns = Size of the list. 
    
  2. CellTable列标题应该是来自服务器的值。 例如。服务器响应:List<Contacts> contacts

    标头应为contacts.getName()

回答

1

我通过以下代码实现了它。

  for (Contacts contact : contacts) { 
       final String city = contact.getCity(); 
       final TextColumn<String> addressColumn = new TextColumn<String>() { 

       @Override 
       public String getValue(Contacts object) { 
        return city; 
       } 
      }; 

      cellTable.addColumn(addressColumn, contact.getAddress()); 
      } 

问候, Gnik

0

使用CellListAsyncDataProvider

//Create a cellList 
@UiField 
CellList<Contact> cellList; 

//Creating dataProvider and completion of the cellList 
@UiFactory 
CellList<Contact> makeCellList() { 
private AsyncDataProvider<Contact> provider = new AsyncDataProvider<Contact>() { 
    @Override 
    public void onRangeChanged(final HasData<Contact> display) { 
     rpcService.getContact(new AsyncCallback<List<Contact>>() { 
       @Override 
       public void onSuccess(List<Contact> result) { 
        display.setRowData(0, result); 
       } 
       @Override 
       public void onFailure(Exception ex) { 
        //TODO 
       } 
     }); 
    } 
}; 

//Adding the cellList to the provider in a constructor 
provider.addDataDisplay(cellList); 

这里是全exampledocs

+0

感谢安德烈。但是我必须使用CellTable而不是CellList。 CellTable是我们客户的要求。 – Prince

+0

无论如何使用'AsyncDataProvider'。这里是适用的[示例](http://www.mytechtip.com/2010/11/gwt-celltable-example-using_8168.html)。 – kapand

相关问题