简体   繁体   English

带UIBinder的GWT CellTable

[英]GWT CellTable with UIBinder

I am trying to display a very simple cellTable on click of a button in my page. 单击页面中的一个按钮,我试图显示一个非常简单的cellTable。 However, the celltable is not getting rendered. 但是,单元格表未呈现。

Giving below code snippets for more understanding: 提供以下代码段以进一步了解:

preview.ui.xml file 楼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 Class: 对应的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;
}  } }

Please guide! 请指导!

Thanks, 谢谢,

Akshay 阿克沙伊

You have two different cellTable objects. 您有两个不同的cellTable对象。 One is created by UiBinder and one is created in your configureCellTable Method. 一种是由UiBinder创建的,另一种是在configureCellTable方法中创建的。

Try to add a SimplePanel in your UiBinder file instead of the table: 尝试在您的UiBinder文件而不是表中添加一个SimplePanel:

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

And in your Java code you add the table on it: 然后在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