1

私は新しい GWTP ユーザーですが、GWTP でテーブルを作成する方法がわかりません。GWTで作成する方法を知っています。

// 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;
  }
};

しかし、これは GWTP では機能しないようです。誰かがGWTPプログラムでボタンを押して値を取得するのを手伝ってくれますか?

4

1 に答える 1

0

1 週間以上前にこの質問をしたことは承知していますが、まだ行き詰まっている可能性があります。Presenterとそれぞれに適切なロジックのビットを配置することを確認する必要がありViewます。

原則として、GWTP を使用しない MVP (Model-View-Presenter) と違いはありません。

あなたには、データを取得して を埋め、それを に渡すPresenter仕事があります。CellTableView

public class TablePresenter extends Presenter<TablePresenter.MyView, TablePresenter.MyProxy>
{
    public interface MyView extends View
    {
        void addData(List<Contact> accounts); // pass data to view
    }

    // proxy and constructor omitted for brevity...

    @Override
    protected void onReveal()
    {
        super.onReveal();

        // server action to get contacts
        dispatchAsync.execute(new GetContacts(), new AsyncCallback<GetContactsResult>()
        {
            @Override
            public void onSuccess(GetContactsResult result)
            {                   
                getView().addData(result.getContacts());
            }
        });
    }
}

には、とそのViewを最初に設定し、からデータを受信する役割があります。ここで、 aと aを使用して aを示します。CellTableColumnPresenterTextColumnColumnButtonCell

public class TableView extends View implements TablePresenter.MyView
{
    @UiField
    CellTable<Contact> table;

    // use a dataprovider to hold the data
    private ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

    // COLUMNS
    TextColumn<Contact> nameColumn;
    Column<Contact, String> buttonColumn;

    @Inject
    public AccountsView(Binder uiBinder)
    {
        initWidget(uiBinder.createAndBindUi(this));

        initTable();
    }

    private void initTable()
    {
        nameColumn = new TextColumn<Contact>()
        {
            @Override
            public String getValue(Contact object)
            {
                return object.name;
            }
        };
        // now add the column to the table
        table.addColumn(nameColumn, "Name");

        buttonColumn = new Column<Contact, String>(new ButtonCell())
        {
            // the text of the button
            @Override
            public String getValue(Contact object)
            {
                return "Delete " + object.name;
            }
        };

        // set the button action
        deleteColumn.setFieldUpdater(new FieldUpdater<Contact, String>()
        {
            @Override
            public void update(int index, Contact object, String value)
            {
                // whatever you want to do when you click the button
                Window.alert("You pressed " + object.name);
            }
        });
        fileTable.addColumn(deleteColumn);

        // link dataprovider to the table
        dataProvider.addDataDisplay(table);
    }

    @Override
    public void addData(List<Contact> contacts)
    {
        // clear the dataProvider's list
        dataProvider.getList().clear();

        // pass the data into the list
        dataProvider.setList(contacts);

    }

}

次に、UiBinder で:

<g:HTMLPanel>
    <b:CellTable ui:field="table" />
</g:HTMLPanel>
于 2014-10-15T10:05:16.587 に答える