我有一个带有编辑按钮和取消按钮的网格 - 非常类似于网格控件的“内联编辑”部分的文档(https://vaadin.com/docs/latest/components/grid#inline-editing -仅限java)。
一切正常。
但是,我想显示整数字段的选择组件 - 选择显示“是”或“否”,并且返回值是整数、1 或 0。
我的“普通”字段编辑器(他们可以在其中输入整数)的代码是:
// integer field
IntegerField txtIsAncillary = new IntegerField();
txtIsAncillary.setWidthFull();
binder.forField(txtIsAncillary).bind(SJRolesQA::getIsAncillary, SJRolesQA::setIsAncillary);
isAncillaryColumn.setEditorComponent(txtIsAncillary);
如何显示链接到整数字段的选择组件?
更新: 我被转换器困住了——我想如果我能得到它——我就能回家了。这就是我正在尝试做的事情:
Select<String> txtIsAncillary = new Select<>();
txtIsAncillary.setItems("Yes","No");
txtIsAncillary.setWidthFull();
binder.forField(txtIsAncillary)
.withConverter(text -> text == "Yes" ? 1 : 0)
.bind(SJRolesQA::getIsAncillary, SJRolesQA::setIsAncillary);
isAncillaryColumn.setEditorComponent(txtIsAncillary);
我确信我在做一些愚蠢的事情 - 但任何帮助将不胜感激。
@cfrick 再次救援!他们为我指明了正确的方向,我能够让转换器使用此代码:
binder.forField(txtIsActiveAncillary)
.withConverter(
text -> "Yes".equals(text) ? 1 : 0,
number -> (number == null) ? "No" : (number == 1 ? "Yes" : "No")
)
.bind(SJRolesQA::getIsActiveAncillary, SJRolesQA::setIsActiveAncillary);
使用“是”和“否”内联编辑选择项并返回 1 或 0 的完整代码如下:
Select<String> mySelect = new Select<>();
mySelect.setItems("Yes","No");
mySelect.setWidthFull();
binder.forField(mySelect)
.withConverter(
text -> "Yes".equals(text) ? 1 : 0,
number -> (number == null) ? "No" : (number == 1 ? "Yes" : "No")
)
.bind(myClass::getIntValue, myClass::setIntValue);
isAncillaryColumn.setEditorComponent(mySelect);