Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
vaadin forms remote validation
Hi,
I am new to vaadin framework, i thinging about porting my application to vaadin before that i want to check whether vaadin supports remote validation for a form element.
Example : I have user id text field for this is need to check this user id already exists using a rest call when ever value in this textfield changes.
is it possible to do in vaadin? if yes please provide example code in your reply.
Prasad
If the rest call is asynchronous (as it should be) you need to handle it pretty much manually. I would hook a custom validation code to a save button click. And then manually set component error for the field that failed the remote validation. This custom code wouldn't rely on Vaadin's field validation, but would be more like bean validation.
Here's some incomplete sample code
public class MyForm extends FormLayout {
private TextField name;
private TextField email;
private BeanFieldGroup<MyPojo> fieldGroup;
public MyForm() {
HorizontalLayout buttons = new HorizontalLayout();
buttons.addComponents(save, cancel);
addComponents(field1, field2, field3, buttons);
fieldGroup = BeanFieldGroup.bindFieldsUnbuffered(yourPojo.clone(), form);
save.addClickListener(e -> validateFields());
}
private void validateFields() {
try {
// first validate with field validation and then with custom
fieldGroup.getFields().forEach(field -> field.validate());
} catch (InvalidValueException e) {
// handle fail
}
// call async rest service to validate field
myRemoteCall(name, this::onRemoteValidationComplete);
}
private void onRemoteValidationComplete(SomeEvent event) {
if (!event.success) {
mySaveToDatabase(fieldGroup.getItemDataSource().getBean());
// Show success message
} else {
event.getField().setComponentError("Failed to remote validate this field");
}
}
}