2013-07-12 7 views
1

내 페이지의 버튼을 클릭하면 매우 간단한 cellTable을 표시하려고합니다. 그러나 셀 테이블이 렌더링되지 않습니다.UIBinder가 포함 된 GWT CellTable

<g:HTMLPanel> 
    <div class="{bundle.css.roundedBorder}"> 
     <table style='width:100%;'> 
      <tr> 
       <td> 
        <c:CellTable pageSize='15' ui:field='cellTable' width="100%"> 
        </c:CellTable> 
       </td> 
      </tr> 
     </table> 
    </div> 
</g:HTMLPanel> 

Correspoding 자바 클래스

preview.ui.xml 파일 :

더 이해 코드 조각 아래주기

public class Preview extends Composite { 
. 
. 
. // other generic GWT code to bind UIBinder XML with this class 
. 
. 
. 

@UiField 
CellTable<Contact> cellTable; 

@UiHandler("button") 
void handleClickOnSearchButton(ClickEvent e) { 
    cellTable = configureCellTable(); 
} 

private CellTable<Contact> configureCellTable() { 
// The list of data to display. 
    List<Contact> CONTACTS = Arrays.asList(new Contact("John", "123 Fourth Road"), new Contact("Mary", "222 Lancer Lane"), new Contact("Zander", "94 Road Street")); 
// 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; 
     } 
    }; 




    // Create address column. 
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() { 
     @Override 
     public String getValue(Contact contact) { 
     return contact.address; 
     } 
    }; 

    // Add the columns. 
    table.addColumn(nameColumn, "Name"); 
    table.addColumn(addressColumn, "Address"); 


    // Create a data provider. 
    ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>(); 

    // Connect the table to the data provider. 
    dataProvider.addDataDisplay(table); 

// Add the data to the data provider, which automatically pushes it to the widget. 
    List<Contact> list = dataProvider.getList(); 
    for (Contact contact : CONTACTS) { 
     list.add(contact); 
    } 


return table; 
} 



private static class Contact { 
private final String address; 
private final String name; 

public Contact(String name, String address) { 
    this.name = name; 
    this.address = address; 
} } } 

안내하십시오!

감사합니다,

하기 Akshay

+0

당신은 그냥 게시하지 않은 귀하의 코드의 일부이지만 귀하의 버튼이 귀하의 uihandler가 작동하지 않는다는 것을 분명히 의미하는 귀하의 ui.xml에 바인딩 된 것을 보지 않을 것입니다. –

답변

2

당신은 두 개의 서로 다른 cellTable 개체가. 하나는 UiBinder에 의해 생성되고 하나는 configureCellTable 메소드에서 생성됩니다. 대신 테이블의 당신의 UiBinder 파일에는 SimplePanel를 추가 할 수

시도 :

<td> 
    <g:SimplePanel ui:field="simplePanel"/> 
</td> 

그리고 자바 코드에서 당신이 그것에 테이블을 추가

어쩌면
@UiField 
SimplePanel simplePanel; 
... 
    private CellTable<Contact> configureCellTable() { 
    ... 
     simplePanel.add(table); 
    }