use of org.kie.workbench.common.forms.processing.engine.handling.FormField 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;
}
use of org.kie.workbench.common.forms.processing.engine.handling.FormField in project kie-wb-common by kiegroup.
the class AbstractFormEngineTest method generateFormField.
public FormField generateFormField(String fieldName, String binding, boolean validateOnChange) {
Widget widget = mock(Widget.class);
IsWidget isWidget = mock(IsWidget.class, withSettings().extraInterfaces(HasValue.class));
when(isWidget.asWidget()).thenReturn(widget);
FormField field = mock(FormField.class);
when(field.getFieldName()).thenReturn(fieldName);
when(field.getFieldBinding()).thenReturn(binding);
when(field.isValidateOnChange()).thenReturn(validateOnChange);
when(field.isBindable()).thenReturn(true);
when(field.getWidget()).thenReturn(isWidget);
when(field.isContentValid()).thenReturn(true);
return field;
}
use of org.kie.workbench.common.forms.processing.engine.handling.FormField in project kie-wb-common by kiegroup.
the class FieldStateValidatorImplTest method testValidateFieldUnexpectedWidget.
@Test
public void testValidateFieldUnexpectedWidget() {
FormField field = mock(FormField.class);
IsWidget widget = mock(IsWidget.class);
when(field.getWidget()).thenReturn(widget);
when(field.isRequired()).thenReturn(true);
assertThatThrownBy(() -> fieldStateValidator.validate(field)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unexpected widget type: impossible to read the value");
}
Aggregations