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.
How to perform validatation OptionGroup
Hi,
1) trying to validate an OptionGroup with multiselect set to true. A Validator was made but the method isValid(Object value) returns the values to validate against inside an Collections$UnmodifiableSet<E>
The question is how to validate that the values in the Collection are indeed only valid values (code sample below) ?
2) Also, the methods setRequired(true) and setRequiredError("Error message") were both sets for that OptionGroup. The red asterisks does displays allright but unfortunately no error mark if no option is selected and the form commit() method is called. Any idea someone ??
public final class MyCustomValidator extends AbstractValidator {
private static final long serialVersionUID = 1L;
private Set<MyCustomParameters> allowedParameters = new HashSet<MyCustomParameters>();
public MyCustomValidator(final String aErrorMessage) {
super(aErrorMessage);
}
public MyCustomValidator(final String aErrorMessage, final Set<MyCustomParameters> aMyCustomParameters) {
this(aErrorMessage);
this.allowedParameters = aMyCustomParameters;
}
@Override
public boolean isValid(final Object value) {
// Problem is here, objects MyCustomParameters are wrapped into Collections$UnmodifiableSet<E>
if (value instanceof MyCustomParameters){
MyCustomParameters oneMyCustomParameters = (MyCustomParameters) value;
if (allowedParameters.contains(oneMyCustomParameters))
return true;
}
return false;
}}