我想添加监听器来改变“。”在可编辑模式下,在vaadin的一个列表中的“,”。 我用BeanItemContainer创建表数据。
答案 0 :(得分:2)
一种选择是使用自定义TableFieldFactory然后将侦听器添加到需要它的每个字段。
https://vaadin.com/book/-/page/components.table.html
table.setTableFieldFactory(new MyTableFieldFactory());
...
public class MyTableFieldFactory extends DefaultFieldFactory {
@Override
public Field createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
String prop = (String) propertyId;
if ("a".equals(prop)) { // propertyId of the column you wish to change
AbstractField f = (AbstractField) super.createField(container, itemId, propertyId, uiContext); // casting to AbstractField to set the field to immediate mode
f.setImmediate(true);
f.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
String val = (String) event.getProperty().getValue();
val = val.replace(".", ",");
event.getProperty().setValue(val);
}
});
return f;
}
return super.createField(container, itemId, propertyId, uiContext);
}
}