use of org.kie.workbench.common.forms.processing.engine.handling.FormValidator.NESTED_PROPERTY_SEPARATOR in project kie-wb-common by kiegroup.
the class DefaultModelValidator method validate.
@Override
public boolean validate(Collection<FormField> fields, MODEL model) {
boolean isValid = true;
if (model instanceof BindableProxy) {
model = ((BindableProxy<MODEL>) model).deepUnwrap();
}
try {
Set<ConstraintViolation<Object>> result = validator.validate(model);
for (ConstraintViolation<Object> constraintViolation : result) {
Optional<FormField> found = fields.stream().filter(formField -> {
Path propertyPath = constraintViolation.getPropertyPath();
String propertyName = propertyPath.iterator().next().getName();
if (checkBinding(formField, propertyName)) {
return true;
}
propertyName = propertyPath.toString().replace(".", NESTED_PROPERTY_SEPARATOR);
if (checkBinding(formField, propertyName)) {
return true;
}
return false;
}).findFirst();
if (!found.isPresent()) {
continue;
}
FormField formField = found.get();
if (formField == null) {
continue;
}
isValid = false;
formField.showError(constraintViolation.getMessage());
}
} catch (IllegalArgumentException ex) {
GWT.log("Error trying to validate model: model does not any validation constraint. ");
}
return isValid;
}
Aggregations