1

我试图在我的页面中单击一个按钮时显示一个非常简单的 cellTable。但是,单元格表没有被渲染。

提供以下代码片段以加深理解:

预览.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>

对应的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;
}  } }

请指导!

谢谢,

阿克谢

4

1 回答 1

2

您有两个不同的 cellTable 对象。一个是由 UiBinder 创建的,一个是在您的 configureCellTable 方法中创建的。

尝试在 UiBinder 文件中添加 SimplePanel 而不是表格:

<td>
    <g:SimplePanel ui:field="simplePanel"/>
</td>

并在您的 Java 代码中添加表格:

@UiField
SimplePanel simplePanel;
...
    private CellTable<Contact> configureCellTable() {
    ...
        simplePanel.add(table);
    }
于 2013-07-15T08:18:01.850 回答