could someone help me. I’m new to gwt and maybe this is so simple. but I can’t seem to figure this out…
I create 2 button for a row in a celltable, each with this method:
protected void addButtonColumn(String header, final IHasValue<Row, Button> hasVal){
Column<Row, String> column = new Column<Row, String>(new TextButtonCell()) {
@Override
public String getValue(Row object) {
return ((Button)hasVal.getValue(object)).getText();
}
};
column.setFieldUpdater(new FieldUpdater<Row, String>() {
@Override
public void update(int index, Row object, String value) {
((Button) hasVal.getValue(object)).click();
}
});
table.addColumn(column, header);
}
I want each button to something different when clicked, but it doesn’t work. i know that i should do something in setfieldupdater but i don’t know what.
Your use of the
TextButtonCellto contain aButton(i.e. a widget) doesn’t really make a lot of sense – wouldn’t it be easier to let the cell have access to the data, and use theValueUpdaterto trigger some kind of behavior based on that data directly?Cells are not widgets – they are much simpler than widgets. This chiefly means two things: they are faster to draw, and stupider. Both of these things are as a result of a single cell instance being used to draw many pieces of data in slightly different ways. If you are going the effort of building a button per element, it doesn’t make sense to use a cell-based widget then – you are nearly drawing everything twice, and getting the worst of both worlds (slow code, that is hard to work with).
Don’t use a
ButtonwithClickHandlers attached, but some other abstraction to deal with clicks, like aCommandinstance for each row, or even better, some kind of handler that accepts the row instance clicked. It might even make sense to have aFieldUpdaterinstance passed in as a parameter for your method (and maybe make theIHasValuegeneric onStringinstead ofButton, so your models don’t need to wrap widgets).(This may not be answering your question directly, but is instead hopefully helping shed some light on why we use cells at all, and how to best write code that takes advantage of cells.)