1

GWT 2.5rc1カスタムテーブルビルダーを使用して、データグリッドの各行のサブテーブルをレンダリングしようとしています。2.5 rc1ショーケース(URL:http ://showcase2.jlabanca-testing.appspot.com/#!CwCustomDataGrid )の例に従いました。新しく追加されたサブ行を表示できますが、サブ行のアンカー要素にクリックハンドラーを追加したいときに問題が発生します。クリックハンドラーが呼び出されることはありません。イベントハンドラーをどこにでも「登録」します。

これが私が今使っているコード「関連部分」です。

private void buildRegRow(Registrazione rowValue,final int absRowIndex, boolean isCommentRow) {
        // Calculate the row styles.
        SelectionModel<? super Registrazione> selectionModel = cellTable.getSelectionModel();
        boolean isSelected =
                (selectionModel == null || rowValue == null) ? false : selectionModel
                        .isSelected(rowValue);
        boolean isEven = absRowIndex % 2 == 0;
        StringBuilder trClasses = new StringBuilder(rowStyle);
        if (isSelected) {
            trClasses.append(selectedRowStyle);
        }

        // Calculate the cell styles.
        String cellStyles = cellStyle;
        if (isSelected) {
            cellStyles += selectedCellStyle;
        }

        if(isCommentRow)
            cellStyles += childCell;

        TableRowBuilder row = startRow();
        row.className(trClasses.toString());

        /*
         * Checkbox column.
         * 
         * This table will uses a checkbox column for selection. Alternatively,
         * you can call dataGrid.setSelectionEnabled(true) to enable mouse
         * selection.
         */
        TableCellBuilder td = row.startTD();
        td.className(cellStyles);
        td.style().outlineStyle(OutlineStyle.NONE).endStyle();
        if (!isCommentRow) {
            renderCell(td, createContext(0), cellTable.getColumn(0), rowValue);
        }
        td.endTD();

        /*
         * View children column.
         * 
         * Displays a link to "show children". When clicked, the list of friends is
         * displayed below the contact.
         */
        td = row.startTD();
        td.className(cellStyles);
        if(!isCommentRow) {
            td.style().outlineStyle(OutlineStyle.NONE).endStyle();
            if(rowValue.hasComments())
                //td.className(CellTableResource.INSTANCE.dataGridStyle().showChildren());
                renderCell(td, createContext(1), cellTable.getColumn(1), rowValue);
        } else {
            td.colSpan(getColumns().size() - 1);

//              // Draw sub-table header
            TableBuilder subTable = td.startTable();
            TableSectionBuilder subTableSection = subTable.startTHead();
            TableRowBuilder tr2 = subTableSection.startTR();
            TableCellBuilder td2 = tr2.startTH();
            td2.text(msgs.date());
            tr2.endTH();
            td2 = tr2.startTH();
            td2.text(msgs.username());
            tr2.endTH();
            td2 = tr2.startTH();
            td2.text(msgs.comment());
            tr2.endTH();
            td2 = tr2.startTH();
            td2.text(msgs.actions());
            tr2.endTH();

            subTableSection.endTR();
            subTable.endTHead();
            subTableSection = subTable.startTBody();
            for(final EntityComment ec : rowValue.getCommentList()) {
                tr2 = subTableSection.startTR();

                // Date
                td2 = tr2.startTD();
                td2.text(DateUtil.getDefaultDateTimeFormat().format(ec.getCreationDate()));
                tr2.endTD();

                // Username
                td2 = tr2.startTD();
                td2.text(ec.getUsername());
                tr2.endTD();

                // Text
                td2 = tr2.startTD();
                td2.text(ec.getText());
                tr2.endTD();

                // Actions
                td2 = tr2.startTD();

                    // Remove
                Anchor removeAnchor = new Anchor("remove");
                removeAnchor.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        Window.alert("clicked");
                    }
                });
                td2.html(new SafeHtmlBuilder().appendHtmlConstant(removeAnchor.toString()).toSafeHtml());
                tr2.endTD();

                subTableSection.endTR();
            }
            subTable.endTBody();
            td.endTable();
        }
        td.endTD();

        for(int i = 2; i <= 6; i++) {
            // Recorded, list name, callcenter, msisdn
            td = row.startTD();
            td.className(cellStyles);
            td.style().outlineStyle(OutlineStyle.NONE).endStyle();
            if(!isCommentRow) {
                renderCell(td, createContext(i), cellTable.getColumn(i), rowValue);
            }
            td.endTD();
        }


        row.endTR();
    }

サブテーブルが表示され、アンカーが正しい位置に表示されますが、クリックハンドラーが呼び出されることはありません。アンカーをレンダリングするために行ったように、ハンドラーコードをページに書き込む方法がわかりません。

助けてくれてありがとう。

4

1 に答える 1

0

カスタム テーブルビルダーを試し、グリッドを作成しました。適切な構造を使用して、任意の要素を追加できます。作成する各要素に必ず一意の ID を設定してください。次に、コードを介して、次のコードを介して要素にアクセスします。

Element e = DOM.getElementById( id );

要素を適切なウィジェットにキャストします。つまり、テキスト入力要素を使用している場合は、いつでもテキスト ボックスにキャストできます。要素をキャストするには、Google で検索できるもう 1 つの手順があります。次に、クリックハンドラーまたは必要なハンドラーを追加します。

于 2012-11-27T04:44:32.697 に答える