Question

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.

Was it helpful?

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top