簡體   English   中英

帶UIBinder的GWT CellTable

[英]GWT CellTable with UIBinder

單擊頁面中的一個按鈕,我試圖顯示一個非常簡單的cellTable。 但是,單元格表未呈現。

提供以下代碼段以進一步了解:

樓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>

對應的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;
}  } }

請指導!

謝謝,

阿克沙伊

您有兩個不同的cellTable對象。 一種是由UiBinder創建的,另一種是在configureCellTable方法中創建的。

嘗試在您的UiBinder文件而不是表中添加一個SimplePanel:

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

然后在Java代碼中添加表格:

@UiField
SimplePanel simplePanel;
...
    private CellTable<Contact> configureCellTable() {
    ...
        simplePanel.add(table);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM