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.
Updating child elements on field validation
Hi,
I have CustomField that splits date and time into their own input fields. And then I have value comparator that validates if field values are in correct order (start before end). But I have problem that I can't get validation errors to show on subelements without refresh. So if my date&time-fields is not valid I would like to show error on all sub fields.
My validator adds valuelistener that does requestRepaintAll() when other end of comparision changes. So validation works correctly, parent fields are validated and errors are shown on them.
I haven't really figured out why things work the way they do. When I have following implementation (on date&time-field) :
@Override
public void validate() throws InvalidValueException {
// boolean subElementErrors = time.getComponentError() != null || date.getComponentError() != null;
try {
super.validate();
updateSubElementError(null);
} catch (InvalidValueException e) {
updateSubElementError(e);
throw e;
} finally {
// requestRepaintAll();
}
}
private void updateSubElementError(ErrorMessage message) {
time.setComponentError(message);
date.setComponentError(message);
}
When I change time field on start field so that start is after end I get validation errors on:
- start.parent
- end.parent
- start.date
- start.time
If I press refresh get validation errors also on end time and date.
If I change start time back to original value then validation errors disappear everywhere except end time and date. And again if I press refresh they get fixed and errors disappear.
So currently other end (that calls requestRepaintAll() on value change) doesn't get updated when I change field value. If I uncomment that requestRepaintALl() from finally block things break down even more, not a single sub field is updated without refresh.
Just tried that I do validation on compare validations other end value changes. If I don't have requestRepaintAll() there it updates all child fields, but if I thien put back the requestRepaintALl() all errors disappear when values are fixed. But if I put invalid value time/date field of same parent doesn't get validation error when date/time field is changed.
I am confuesd.
Hi,
As the javadoc mentions (but not very clearly): "Validators must not have any side effects". This is because validators are run late in the render process, and any changes done to other component might not make it into the response - and strange effects will occur, like you are seeing.
Best Regards,
Marc
P.S You might also want to take a look at the changes made to validation (and Form) in Vaadin 7 alpha 1.