我有一个 Vaadin 8 Grid,我想在其中将一列设置为可编辑。为此,我有 where Food.calories
is a long (是的,在这种情况下它可能是 int 但请记住,这是一个示例,我的特定用例需要 long):
Binder<Food> binder = foodGrid.getEditor().getBinder();
TextField caloriesTextField = new TextField();
binder.forField(caloriesTextField)
.withValidator(CustomCaloryValidator::isValidValue, "Must be valid a positive amount")
.withConverter(new StringToCaloriesConverter("Must be an integer"))
.bind(Food::getCalories, Food::setCalories);
// This line fails with the error because the types do not match.
foodGrid.addColumn(Food::getCalories, new NumberRenderer(myNumberFormat))
.setEditorComponent(new TextField(), Food::setCalories);
不幸的是,这不起作用并且有以下错误:
类型参数“C”的推断类型“C”不在其范围内;应该实现'com.vaadin.data.HasValue'
我到处寻找,除了简单的编辑之外,找不到任何示例。演示采样器确实有一个使用滑块的更复杂的示例,但我无法弄清楚如何从该示例中推断出......
我理解错误,它试图将 long 映射到字符串。但是我找不到将转换器添加到 addColumn 以使其工作的方法...