1
我想顯示一個非常簡單的cellTable點擊我的網頁中的按鈕。 但是,celltable沒有得到渲染。GWT CellTable與UIBinder
得到下述代碼段爲更多的理解:
preview.ui.xml文件
<g:HTMLPanel>
<div class="{bundle.css.roundedBorder}">
<table style='width:100%;'>
<tr>
<td>
<c:CellTable pageSize='15' ui:field='cellTable' width="100%">
</c:CellTable>
</td>
</tr>
</table>
</div>
</g:HTMLPanel>
Correspoding的Java類:
public class Preview extends Composite {
.
.
. // other generic GWT code to bind UIBinder XML with this class
.
.
.
@UiField
CellTable<Contact> cellTable;
@UiHandler("button")
void handleClickOnSearchButton(ClickEvent e) {
cellTable = configureCellTable();
}
private CellTable<Contact> configureCellTable() {
// The list of data to display.
List<Contact> CONTACTS = Arrays.asList(new Contact("John", "123 Fourth Road"), new Contact("Mary", "222 Lancer Lane"), new Contact("Zander", "94 Road Street"));
// Create a CellTable.
CellTable<Contact> table = new CellTable<Contact>();
// Create name column.
TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact contact) {
return contact.name;
}
};
// Create address column.
TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact contact) {
return contact.address;
}
};
// Add the columns.
table.addColumn(nameColumn, "Name");
table.addColumn(addressColumn, "Address");
// Create a data provider.
ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Add the data to the data provider, which automatically pushes it to the widget.
List<Contact> list = dataProvider.getList();
for (Contact contact : CONTACTS) {
list.add(contact);
}
return table;
}
private static class Contact {
private final String address;
private final String name;
public Contact(String name, String address) {
this.name = name;
this.address = address;
} } }
請指導!
感謝,
阿克沙伊
也許你只是沒有張貼你的代碼的一部分,但我沒有看到你的按鈕綁定在你的ui.xml中,這顯然意味着你的uihandler不起作用。 –