0

I have a widget that I render in a GWT cell, which extends the AbstractCell, via the render function below. The column is created as below with the getValue and the FieldUpdater (update) function being defined. The intent is to set selected row to correspond to the clicked widget. However, when I click on the widget, the onBrowserEvent function of the cell is not called. I think this is happening because the widget in question contains a FlexTable within it.

I verified this by setting a breakpoint in the function AbstractCellTable.onBrowserEvent2 and noticed that the function does not fire a cell event since the else if (section == getTableBodyElement())

return false. This is false because the section is a sub-section of the table body element corresponding to the table that I inserted via the widget.

Is there a way to pass the click in the inner table (widget) to the outer cell table?

//Render function to add widget to cell
public void render(Context context, MyItem value, SafeHtmlBuilder sb) {
    if (value != null) {
        SafeHtml safeValue = SafeHtmlUtils.fromTrustedString(value
            .getWidget().getElement().getString());
        sb.append(safeValue);
    }
}


//Creating the corresponding column, setting up the field update, 
// and adding the column to cell table

// Create Cell
MyItemCell myItemCell = new MyItemCell();

// Create Column
Column<MyItem, MyItem> myItemColumn = new Column<MyItem, MyItem>(myItemCell) {

    @Override
    public MyItem getValue(MyItem object) {
        return object;
    }

};

// add field updater
myItemColumn.setFieldUpdater(new FieldUpdater<MyItem, MyItem>() {
    @Override
    public void update(int index, MyItem object, MyItem value) {
        // This function, for some reason, 
        // is not getting called when I click 
        // on the widget corresponding to MyItem
        MyDataTable.this.getSelectionModel().setSelected(object, true);
    }
});


// Add column to table
this.getDataTable().addColumn(myItemColumn);
AshD
  • 1,066
  • 2
  • 13
  • 28

1 Answers1

2
FieldUpdater method is called when updating values in the column.

To catch click event, if I am not wrong then MyItemCell is your custom cell. so inside that cell implement onBrowserEvent event and handle click event there.

 public void onBrowserEvent(final Event event) {
            // TODO Auto-generated method stub
            super.onBrowserEvent(event);
            if (DOM.eventGetType(event) == Event.ONCLICK) {
                    System.out.println("event type -->> " + event.getType());
            }

        }
bNd
  • 7,512
  • 7
  • 39
  • 72
  • Thank you. In my debugger, I do not see the function onBrowserEvent being called for the MyItemCell when I click on the widget portion that I rendered in the cell. When I click outside the widget (but in the cell), I do hit the breakpoint in the onBrowserEvent function. Any tips? – AshD May 30 '13 at 16:56
  • Note that I am calling the AbstractCell parent constructor with the following arguments in the constructor of MyItemCell: super(click", "keydown", "change") – AshD May 30 '13 at 17:19
  • @user2434608 You have to disable KeyboardSelectionPolicy of CellTable. i.e. `cellTable..setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);` – bNd May 31 '13 at 05:01