9

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>

プログラムで列を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>

しかし、次のエラーが発生します。

[エラー] [方言] - 予期しない子要素が見つかりました Element addStyleNames='{style.titleColumn}'ui:field='titleColumn'> (:33)

UiBinder を使用して CellTable 全体を定義するにはどうすればよいですか?

4

1 に答える 1

5

明らかに、2 番目のリストでは、列を子オブジェクトとして追加しようとしています。セル テーブルは子を直接受け入れません (つまり、addChild(...) メソッドはありません)。

固定数の列があり、UIBinder を使用したい場合は、単なる HTML テーブルの使用を検討してください。その場合、XML ファイルにすべての列が含まれますが、テーブルの操作が難しくなります (Widget ではなく 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) のように。こんなことをしても無駄だと思います。

于 2012-08-06T18:08:47.700 に答える