-->

定义GWT CellTables用UiBinder的(Defining GWT CellTables

2019-07-30 18:12发布

如果我定义我在这样MyView.ui.xml UiBinder的文件CellTable:

<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"
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default' xmlns:p1="urn:import:com.google.gwt.user.cellview.client">
        ...
    <g:HTMLPanel>           
      <c:CellTable
        addStyleNames='{style.cellTable}'
        pageSize='15'
        ui:field='cellTable' width="100%">  
       </c:CellTable>           
    </g:HTMLPanel>

然后programmaticaly列添加到CellTable,一切工作正常。

但在试图减少样板代码,我想在我的UiBinder的文件还定义表格列。 我已经试过这样:

    ...
    <g:HTMLPanel>           
      <c:CellTable
        addStyleNames='{style.cellTable}'
        pageSize='15'
        ui:field='cellTable' width="100%">  
            <c:TextColumn 
                addStyleNames='{style.titleColumn}'
                ui:field="titleColumn"/>
       </c:CellTable>           
    </g:HTMLPanel>

但它产生以下错误:

[错误] [dialective] - 实测值意外子元素元素addStyleNames = '{} style.titleColumn' UI:字段= 'titleColumn'>(33)

我怎么能使用UiBinder的定义整个CellTable?

Answer 1:

显然,在第二上市你想增加一列作为子对象。 细胞表不直接接受孩子(意思是没有的addChild(...)方法)。

如果你有固定的列数和要使用UiBinder的考虑使用单纯的HTML表格。 在这种情况下,你会在XML文件中的所有列,但该表将变得更难与工作 - 的HtmlElement不小部件。

<table ui:field="table">
    <col ui:field="firstColumn" class="{style.firstColumn}">
    <col ui:field="secondColumn"  class="{style.secondColumn}">
    ...
</table>

和代码可能看起来像以下

... 
@UiField
private TableColElement firstColumn;

@UiField
private TableColElement secondColumn;

但与表中的所有其他业务将通过DOM。 像table.appentChild(rowElement)。 我觉得做这样做不值得。



文章来源: Defining GWT CellTables with UiBinder