I have the columns Minimum
and Maximum
in Vaadin 8 Grid
.
These columns are editable. I need to make validators also check these 2 values against one another
so that if the value entered in field Maximum
is less than the value of Minimum
entry in that row,
the validator will issue an error and vice versa.
the code is as follows:
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)
);
How can this be done in Vaadin 8? How to pass the value of another cell to the validator?
TIA
//--------------------
I tried adding the following validator to the "max" column after the other two validators:
.withValidator(v -> v>=((Float)grid.getColumn("min")
.getEditorBinding().getField().getValue()),
"Incorrect range")
This validator is never passing anything - always issues the error "Incorrect range".
//--------------------
more accurately - tried the following validator and it works.
.withValidator(v -> v>=(Float.parseFloat((String)(grid.getColumn("min")
.getEditorBinding().getField().getValue()))),
"Incorrect range")
however - the numbers are displayed with formatting (,
between every 3 digits) and validator is attempting to read it as a number - without the format. This still throwing the error unless i get rid of those comma-s while editing. Will ask this in another Q.
The second edit in the question solved it. I got around the number format issue by explicitly converting the String
back from the formatted form before passing to parseFloat()
. Works fully to the effect.