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.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 2 weeks ago
BeanValidationBinder and Domain class with Optional in getter
If domain class contain getter with Optional type of returned value:
public Optional<String> getName() {
return Optional.ofNullable(name);
}
And use BeanValidationBinder :
BeanValidationBinder<Employee> binder = new BeanValidationBinder<>(Employee.class);
binder.forField(name).withValidationStatusHandler(new BindingValidationStatusHandler() {
private static final long serialVersionUID = 1L;
@Override
public void statusChange(BindingValidationStatus<?> statusChange) {
if (statusChange.getMessage().isPresent()) {
name.setComponentError(new UserError(statusChange.getMessage().get()));
} else {
name.setComponentError(null);
}
}
})
.bind("name");
After data input in field appear error:
...
Caused by: java.lang.ClassCastException: Cannot cast java.lang.String to java.util.Optional
...
Source code to reproduce error:
https://github.com/zesetup/vaadin8binder.git
Last updated on
You cannot reply to this thread.