为了账号安全,请及时绑定邮箱和手机立即绑定

Vaadin 8 - 网格验证器可以“听到”跨单元格的值

Vaadin 8 - 网格验证器可以“听到”跨单元格的值

达令说 2021-07-09 14:15:08
我有列Minimum和MaximumVaadin 8 Grid。这些列是可编辑的。我需要让验证器还相互检查这 2 个值,以便如果在字段中输入的值Maximum小于Minimum该行中的条目值,验证器将发出错误,反之亦然。代码如下:grid.addColumn(AuditParams::getMaxAmt, new NumberRenderer()).setId("max").setCaption("Max").setEditorBinding(grid        .getEditor()        .getBinder()        .forField(new TextField())        .withConverter(new StringToFloatConverter("Enter a value greater than 0"))           .withValidator(v -> v>0.0f, "Must be a positive value")           .withValidator(v -> v<Constants.MAX_AMT, "Maximum can be "+Constants.MAX_AMT)        .bind(AuditParams::getMaxAmt, AuditParams::setMaxAmt));如何在 Vaadin 8 中做到这一点?如何将另一个单元格的值传递给验证器?TIA//--------------------我尝试在其他两个验证器之后将以下验证器添加到“max”列:           .withValidator(v -> v>=((Float)grid.getColumn("min")               .getEditorBinding().getField().getValue()),                "Incorrect range")这个验证器永远不会传递任何东西 - 总是发出错误“不正确的范围”。//--------------------更准确地 - 尝试了以下验证器并且它有效。           .withValidator(v -> v>=(Float.parseFloat((String)(grid.getColumn("min")               .getEditorBinding().getField().getValue()))),                "Incorrect range")但是 - 数字以格式显示(,每 3 位数字之间)并且验证器试图将其作为数字读取 - 没有格式。除非我在编辑时去掉那些逗号,否则这仍然会抛出错误。会在另一个 Q 中问这个。
查看完整描述

2 回答

?
慕村225694

TA贡献1880条经验 获得超4个赞

问题中的第二个编辑解决了它。我通过String在传递到parseFloat(). 完全发挥作用。


查看完整回答
反对 回复 2021-07-14
  • 2 回答
  • 0 关注
  • 124 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信