0

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.

sujikin
  • 351
  • 3
  • 11

2 Answers2

0

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.

bNd
  • 7,512
  • 7
  • 39
  • 72
  • how to fire a dummy browser event then which will help to fire the onBrowserEvent or any other solution? – sujikin May 15 '13 at 13:47
  • I don't understand what you tried but if radio button is for your record selection then you have to use `CheckboxCell` instead of radio and use `createCheckboxManager`. Other wise fire Dom event just example http://stackoverflow.com/questions/16542266/handler-on-dom-elements-in-gwt/16542675#16542675 – bNd May 15 '13 at 14:06
  • Radio button is used because only one record can be selected at a time. Let me check that link. – sujikin May 15 '13 at 14:19
  • And also refer this link http://thoughtsofthree.com/2011/02/creating-a-gwt-radiobuttoncell/ – bNd May 15 '13 at 14:49
  • I have used that idea only. Just that it needs to be updated for GWT 2.5. The method signatures have changed in the latest release. – sujikin May 15 '13 at 14:54
0

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()));
            }
          }
        });
sujikin
  • 351
  • 3
  • 11