2012-08-15 44 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的显示器。