When a REST endpoint returns an validation error I want to reflect the validation message in the corresponding vaadin input field. In this example I would like to have an error message near to the password input field. So the user is able to fix the error easily.
@Route("create-customer")
public class CreateCustomerView extends Div {
public CreateCustomerView(RestClientService restClientService) {
TextField firstName = new TextField("First name");
DatePicker birthDay = new DatePicker("Birthday");
PasswordField password = new PasswordField("Password");
Button submit = new Button("Submit", (ComponentEventListener<ClickEvent<Button>>) event -> restClientService.createCustomer(
new RegisterCustomerRequest(firstName.getValue(), birthDay.getValue(), password.getValue())));
FormLayout formLayout = new FormLayout();
formLayout.add(firstName, password, submit);
add(formLayout);
}
}
My repsonse is very standard and verbose.
{
"timestamp": "2022-09-17T12:39:55.642883700",
"status": 400,
"error": "ConstraintViolationException",
"message": "Some arguments are not valid.",
"fieldErrors": [
{
"field": "register.registerCustomerCommand.password",
"error": "com.example.application.service.RegisterCustomerService register.registerCustomerCommand.password: # a digit must occur at least once\n# a lower case letter must etc. etc."
}
],
"path": "/v1/customers/"
}
Is it possible with vaadin out of the box? Binder seems to be good for client side validation errors but my errors depend on the server side validation on the request.