2012-08-15 100 views
1

嗨我是GWT新手,所以也是GWTP。GWTP:顯示CellTable的問題

我嘗試使用CellTables,我決定先在developers.google.com/web-toolkit/doc/2.4/DevGuideUiCellWidgets#celltable上構建一個簡單的GWT文檔,然後我調整了幾個匹配GWTP MVP的內容設計。

首先,我創建了Celltable我View.ui.xml文件:

xmlns:c="urn:import:com.google.gwt.user.cellview.client"> 
<g:HTMLPanel> 
    <c:CellTable pageSize='15' ui:field='cellTable' /> 
</g:HTMLPanel> 

然後,我創建了一個類聯繫人:

public class Contact { 
    private final String address; 
    private final String name; 

    public Contact(String name, String address) { 
     this.name = name; 
     this.address = address; 
    } 

    public String getAddress() { 
     return address; 
    } 

    public String getName() { 
     return name; 
    } 
} 
我View.java文件

​​

最後在我的Presenter.java文件中:

public interface MyView extends View { 
    CellTable<Contact> getCellTable(); 
} 

@Override 
protected void onReset() { 
    super.onReset(); 

    // Create name column. 
    TextColumn<Contact> nameColumn = new TextColumn<Contact>() { 
      @Override 
      public String getValue(Contact contact) { 
      return contact.getName(); 
      } 
     }; 

    // Create address column. 
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() { 
      @Override 
      public String getValue(Contact contact) { 
      return contact.getAddress(); 
      } 
     }; 

    // Add the columns. 
    getView().getCellTable().addColumn(nameColumn, "Name"); 
    getView().getCellTable().addColumn(addressColumn, "Address"); 

    // Set the total row count. 
    getView().getCellTable().setRowCount(CONTACTS.size(), true); 

    // Push the data into the widget. 
    getView().getCellTable().setRowData(0, CONTACTS); 
} 

一切似乎都對我很好,但沒有CellTable顯示,當我嘗試此代碼...而且我沒有得到任何錯誤...

預先感謝您的幫助!

回答

0

它看起來像你沒有使用/有DataProvider註冊您的CellTable。 GWT CellWidgets基於DataProvider/DIsplay模式。所以CellTable只是你的DataProvider的一個Display。一個DataProvider可以有多個顯示。

你不需要寫:

// Set the total row count. 
getView().getCellTable().setRowCount(CONTACTS.size(), true); 

// Push the data into the widget. 
getView().getCellTable().setRowData(0, CONTACTS); 

您需要註冊您的CellTable爲您的DataProvider(如ListDataProvider),比調用刷新方法,當你用新數據更新的DataProvider的顯示器。