I have written below code in a celltable constructor

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

The below method is called when a custom radio cell is selected

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

}

After removing Window.alert it does not work anymore and the onBrowserEvent of cell is not getting called. I tried removing addSelectionChangeHandler and still the problem is there.

Note: The above idea works without this addSelectionChangeHandler, if you move between the rows using keys and then press enter. I wanted instead that it should work with click only and no keyboard pressing.

有帮助吗?

解决方案 2

I removed the addSelectionChangeHandler and added the below and it worked

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

其他提示

Because onBrowserEvent is Fired whenever a browser event is received.. when Window.alert method called then alert display focus goes to the alert window, the parent window generates unload event.so due to this event onBrowserEvent fired.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top