GWT DataGrid不可见(UIBinder和LazyPanel)

时间:2013-12-16 20:24:34

标签: gwt datagrid uibinder

我正在构建一个GWT应用程序。

在这个应用程序中,我有许多DataGrid实现,显示从服务器检索的数据。在一个面板中,我有一个TabLayoutPanel,每个选项卡上都有一个DataGrid。

当父标签变为可见时,我试图延迟加载DataGrids。

这是ui.xml:

<g:TabLayoutPanel width="800px" height="450px" barUnit='EM' barHeight='3'>
<g:tab>
  <g:header size='7'><b>Volunteer Assignments</b></g:header>
  <grid:VolunteerAssignmentGrid/>
</g:tab>
<g:tab>
  <g:header size='7'><b>Volunteer Details</b></g:header>
  <g:LazyPanel ui:field="lazyDetails">
    <grid:VolunteerFieldsGrid/>       
  </g:LazyPanel>
</g:tab>
</g:TabLayoutPanel>

在上面的代码中,VolunteerAssignmentGrid和VolunteerFieldsGrid是DataGrid的子类。

VolunteerAssignmentGrid立即可见,数据显示OK。

但是,下一个选项卡上的VolunteerFieldsGrid根本不显示。

奇怪的是,在正确的时间(当我点击其他选项卡时)请求数据,并且服务器响应是正确的。好像桌子不可见。

为什么第二个DataGrid不可见的任何想法?

编辑:

UiBinder课程:

public class VolunteerDetailsPanel extends DialogBox {

interface Binder extends UiBinder<Widget, VolunteerDetailsPanel> {}
private static final Binder binder = GWT.create(Binder.class);

@UiField LazyPanel lazyDetails;
private Record volunteerRecord;
private String fullName;
private String volunteerId;

public VolunteerDetailsPanel(Record record) {
    this.volunteerRecord = record;
    fullName = volunteerRecord.getValue("forename")+" "+volunteerRecord.getValue("surname");
    volunteerId = volunteerRecord.getValue("id");
    setText(fullName);
}

public void initComponent() {
    setWidget(binder.createAndBindUi(this));
}

@UiFactory VolunteerAssignmentGrid createAssignmentGrid() {
    return new VolunteerAssignmentGrid(volunteerId, fullName);
}

@UiFactory VolunteerFieldsGrid createFieldsGrid() {
    return new VolunteerFieldsGrid(volunteerId);
}


}

根据要求,还有VolunteerFieldsGrid类。它扩展了ListGrid(我的一个,但是在这里发布的时间太长了,我所有的其他网格都扩展它并且没问题),这反过来扩展了GWT的DataGrid:

public class VolunteerFieldsGrid extends ListGrid {

public VolunteerFieldsGrid(String volunteerId) {

    super(100, "name", false);
    setWidth("100%");

    ListGridColumn<?>[] columns = new ListGridColumn<?>[] {
        new FieldNameColumn("Field", "name").width(75),
        new TextColumn("Value", "value").width(300)
    };
    setColumns(columns);

    ListGridDataProvider data = ListGridDataProvider.getInstance("field",
            "/volunteer/"+volunteerId, "name", false);

    setDataProvider(data);
}

}

1 个答案:

答案 0 :(得分:0)

您必须在SelectionEvent中注册TabLayoutPanel的处理程序,该处理程序将调用LazyPanel.setVisible(true)。在UiBinder中尝试这样的事情:

@UiHandler("yourTabPanelUiField")
void onSelectionEvent(SelectionEvent event) {
  //for extra functionality check if EventTarget equals the correct tab
  lazyDetails.setVisible(true);
}
相关问题