无法调用Celltable onBrowserEvent

时间:2013-05-15 12:58:42

标签: gwt celltable selectionmodel

我在单元格构造函数

中编写了以下代码
 public ViewSubscriptionsCellTable(CellTableResource resource, final WidgetListener clickListener) {
        super(15, resource);
        this.resource = resource;
        setStyleName(CSS.LISTDATATABLE);
        setPageStart(0);
        expandedRows = new HashSet<String>();
        selectionModel = new SingleSelectionModel<ViewSubscriptionsWrapper>();
        setSelectionModel(selectionModel);
        selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler(){
            @Override
            public void onSelectionChange(SelectionChangeEvent event) {
                Window.alert("clicked");
            }
        });
        List<ViewSubscriptionsWrapper> viewSubscriptionsWrapperList = new ArrayList<ViewSubscriptionsWrapper>(); 
        setTableBuilder(new CustomTableBuilder());
        createColumns(clickListener);
        listDataProvider = new ListDataProvider<ViewSubscriptionsWrapper>(new ArrayList<ViewSubscriptionsWrapper>());
        listDataProvider.addDataDisplay(ViewSubscriptionsCellTable.this);
        createSortHandler();
        pager = new PagerWidget(TextLocation.CENTER);
        pager.setStyleName(CSS.WIDGET_TEXT_FONT);
        pager.setDisplay(ViewSubscriptionsCellTable.this);
        this.setColumnWidth(radioColumn, 5.0, Unit.PCT);
        this.setColumnWidth(msisdnColumn, 5.0, Unit.PCT);
        this.setColumnWidth(subscriptionColumn, 10.0, Unit.PCT);
        this.setColumnWidth(simTypeColumn, 10.0, Unit.PCT);
        this.setColumnWidth(simNumberColumn, 70.0, Unit.PCT);
    }

选择自定义无线电单元时调用以下方法

@Override
public void onBrowserEvent(Context context, Element elem, ViewSubscriptionsWrapper object, NativeEvent event) {
super.onBrowserEvent(context, elem, object, event);
clickListener.onWidgetEvent(new WidgetEvent(object, context.getIndex()));

}

删除Window.alert后,它不再起作用,并且单元格的onBrowserEvent是  没有被召唤。我尝试删除addSelectionChangeHandler仍然是问题所在 那里。

注意: 如果在行之间移动,上述想法在没有此addSelectionChangeHandler的情况下可以正常工作 使用键然后按Enter键。我想要它应该只使用点击而不按键盘。

2 个答案:

答案 0 :(得分:0)

因为只要收到浏览器事件,onBrowserEvent就会被触发..当Window.alert方法被调用时,警告显示焦点转到 在警告窗口中,父窗口生成卸载事件。因为此事件onBrowserEvent被触发。

答案 1 :(得分:0)

我删除了addSelectionChangeHandler,并添加了以下内容并且工作正常

this.addCellPreviewHandler(new Handler<ViewSubscriptionsWrapper>() {
          @Override
          public void onCellPreview(CellPreviewEvent<ViewSubscriptionsWrapper> event) {
              ViewSubscriptionsWrapper sample = event.getValue();
            if ("click".equals(event.getNativeEvent().getType())) {
                clickListener.onWidgetEvent(new WidgetEvent(sample, event.getIndex()));
            }
          }
        });