저는 새로운 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 프로그램에서 버튼을 눌러 값을 얻는 데 도움을 줄 수 있습니까?
나는 당신이 일주일 전에이 질문을 한 것을 알고 있지만 여전히 그것에 갇혀있을 수 있으므로 여기에 있습니다. Presenter
및 View
각각 에 올바른 논리를 입력했는지 확인하기 만하면 됩니다.
원칙적으로 GWTP가없는 MVP (Model-View-Presenter)와 다르지 않습니다.
귀하는 Presenter
을 채우기 위해 데이터를 가져 오는 일이있다 CellTable
, 그리고 그것을 통과를 View
:
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
처음에 설정하는 작업이 CellTable
그 Column
들뿐만 아니라에서 데이터를 수신 Presenter
. 여기에 a TextColumn
와 a를 Column
사용하여 보여줍니다 ButtonCell
.
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>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다