Grid: custom validation for grid editor by row

Hi,

I have a simple grid that represent my entities whith an editor for some of the fields.
The entities have a property named “type” (which is an Enum by the way).

I would like to set a custom/different validation for the same fields in the grid depending on the “type” property.

Is there a way to do that? Or maybe I should think of something else than a grid representation of my entities?
The workaround that I implement is separate grids for entities of different types and separate validators.
Is it possible to achieve in one grid?

You could add bean level validator in the following manner. Say for example you have a “property” and if your “type” is SOMETHING1 you want to validate “property” being positive and when SOMETHING2 negative, it goes like this:

binder.withValidator(Validator.from(item -> {
	if (item.getType().equals(Type.SOMETHING1))
		return item.getProperty() > 0;
	else if (item.getType().equals(Type.SOMETHING2)) (
		return item.getProperty() < 0;
	else {
		return false;
},"Must be positive"));

Thanks for the reply. I’ve managed to add a Validator in my view class with the grid and override apply() method. Now I just need to move it somewhere outside this class :wink: