2014-10-03 3 views
1

새로운 GWTP 사용자이며 GWTP에서 테이블을 만드는 방법을 모르겠습니다. 나는 GWT에서 하나 만드는 법을 안다.GWTP에서 동적 테이블을 만드는 방법

// 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 프로그램의 버튼 누르기에서 값을 가져 오는 것을 도와 줄 수 있습니까?

+0

나는 그것을 사용하지 않는했지만, 난 당신이 할 수 가능성이있는 ActionCell과 단추 형 전지 클래스가 있다고 생각 사용. 그 중 하나를 검색해보고 도움이되는지 확인하십시오. – britter

답변

0

1 주일 전에이 질문에 대한 답변을 얻었지만 여전히 여기에 머물러있을 수 있으므로 여기를 클릭하십시오. PresenterView에 올바른 논리 비트를 각각 입력해야합니다.

은 원칙적으로 GWTP없이 MVP (모델 -보기 - 발표자)과 다르지 없습니다 :

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()); 
      } 
     }); 
    } 
} 
:

귀하의 PresenterCellTable을 채우기 위해 데이터를 가져 오는하고 View에 전달하는 일이있다

View은 처음에는 CellTable 및 그 Column을 설정하고 Presenter에서 데이터를 수신하는 작업을 수행합니다. 당신의 UiBinder에 그런

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); 

    } 

} 

: 여기가 TextColumnColumnButtonCell를 사용하여 보여

<g:HTMLPanel> 
    <b:CellTable ui:field="table" /> 
</g:HTMLPanel> 
관련 문제