我想在我的页面上使用从服务器接收的数据UIBinder
创建。CellTable
我想我不太明白UiBinder
. 打电话前initWidget()
我应该做什么,不应该做什么?
当我删除对configureDataProvider()
表的调用时,会出现,但它是空的,进度条正在运行。当我包含configureDataProvider()
时,表格根本不会呈现。
请你能解释一下这里发生了什么吗?
@UiField(provided = true)
VerticalPanel tableSelection;
@UiField(provided = true)
Anchor productTableAnchor;
@UiField(provided = true)
Anchor ordersTableAnchor;
@UiField(provided = true)
Anchor staffTableAnchor;
List<ProductDTO> products;
@UiField(provided = true)
CellTable<ProductDTO> productTable;
@UiField(provided = true)
SimplePager pager;
public TableSelectionWidget() {
SimplePager.Resources pagerResources = GWT
.create(SimplePager.Resources.class);
tableSelection = new VerticalPanel();
productTableAnchor = new Anchor();
ordersTableAnchor = new Anchor();
staffTableAnchor = new Anchor();
productTable = new CellTable<ProductDTO>();
productTable.setPageSize(10);
configureTable();
pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0,
true);
pager.setDisplay(productTable);
initWidget(uiBinder.createAndBindUi(this));
}
private void configureTable() {
Column<ProductDTO, String> nameColumn = new Column<ProductDTO, String>(
new TextCell()) {
@Override
public String getValue(ProductDTO object) {
return object.getName();
}
};
Column<ProductDTO, String> priceColumn = new Column<ProductDTO, String>(
new TextCell()) {
@Override
public String getValue(ProductDTO object) {
return object.getPrice().toString();
}
};
Column<ProductDTO, String> quantityColumn = new Column<ProductDTO, String>(
new TextCell()) {
@Override
public String getValue(ProductDTO object) {
return String.valueOf(object.getQuantity());
}
};
productTable.addColumn(nameColumn, "Name");
productTable.addColumn(priceColumn, "Price");
productTable.addColumn(quantityColumn, "Qty");
configureDataProvider();
}
private void configureDataProvider() {
AsyncDataProvider<ProductDTO> provider = new AsyncDataProvider<ProductDTO>() {
@Override
protected void onRangeChanged(HasData<ProductDTO> display) {
final int start = display.getVisibleRange().getStart();
int length = display.getVisibleRange().getLength();
AsyncCallback<List<ProductDTO>> callback = new AsyncCallback<List<ProductDTO>>() {
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
public void onSuccess(List<ProductDTO> result) {
products = result;
updateRowData(start, result);
}
};
productService.getAllProducts(callback);
}
};
provider.addDataDisplay(productTable);
provider.updateRowCount(products.size(), true);
}
编辑添加了 ui.xml
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:c="urn:import:com.google.gwt.user.cellview.client"
xmlns:ct="urn:import:com.ooo1sk.client.widgets">
<ui:style>
</ui:style>
<g:HTMLPanel>
<g:VerticalPanel styleName="" ui:field="tableSelection">
<g:Anchor ui:field="ordersTableAnchor" text="Orders"></g:Anchor>
<g:Anchor ui:field="productTableAnchor" text="Product"></g:Anchor>
<g:Anchor ui:field="staffTableAnchor" text="Staff"></g:Anchor>
</g:VerticalPanel>
<g:HTMLPanel>
<table cellspacing='0' cellpadding='0' style='width:100%;'>
<tr>
<td valign='top'>
<c:CellTable addStyleNames='infoTable' pageSize='15'
ui:field='productTable' />
</td>
</tr>
<tr>
<td align='center'>
<c:SimplePager ui:field='pager' />
</td>
</tr>
</table>
</g:HTMLPanel>
</g:HTMLPanel>
</ui:UiBinder>
UPD:更改后它可以工作,但只显示前 15 行,但是 Pager 显示所有 91 行并在单击后更改编号。
private void configureDataProvider() {
AsyncDataProvider<ProductDTO> provider = new AsyncDataProvider<ProductDTO>() {
@Override
protected void onRangeChanged(HasData<ProductDTO> display) {
final int start = display.getVisibleRange().getStart();
final int length = display.getVisibleRange().getLength();
productService
.getAllProducts(new AsyncCallback<List<ProductDTO>>() {
public void onSuccess(List<ProductDTO> result) {
label.setText("start " + start + " "
+ "resultsize " + result.size() + " "
+ "length " + length);
products = result;
updateRowCount(result.size(), true);
updateRowData(start, result);
}
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
});
}
};
provider.addDataDisplay(productTable);
}
好的,玩数字解决了这个问题。在updateRowData(start, result);
我改为start
现在0
它工作正常。不过,我将非常感谢专家对此的任何评论。