嗨,我是GWT的新手,所以我也是GWTP的新手。
我尝试使用GWTP,我决定从构建一个简单的GWTP开始,遵循developers.google.com/web-toolkit/doc/2.4/DevGuideUiCellWidgets#celltable上的CellTables文档,我调整了一些东西来匹配GWTP设计。
首先,我在View.ui.xml文件上创建了我的Celltable:
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文件中:
@UiField(provided=true) CellTable<Contact> cellTable = new CellTable<Contact>();
public CellTable<Contact> getCellTable() {
return cellTable;
}最后在我的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);
}对我来说一切似乎都很好,但是当我尝试这个code...And时没有显示CellTable,我没有得到任何错误...
提前感谢您的帮助!
发布于 2012-10-05 06:05:50
看起来你没有为你的CellTable使用/注册DataProvider。GWT是基于CellWidgets /DIsplay模式的。所以CellTable只是你的DataProvider的一个显示器。一个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时调用refresh方法。
https://stackoverflow.com/questions/11976915
复制相似问题