Question

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);
Was it helpful?

Solution

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

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