component errors added automatically on validate()?

Hi,

quoting from the Book of Vaadin (https://vaadin.com/book/-/page/application.errors.html): [quote]
All components have a built-in error indicator that can be set explicitly with setComponentError() or can be turned on implicitly if validating the component fails
[/quote].

However,
a) creating a TextField called “username”,
b) setting it as “required”,
c) not filling it with data,
d) and calling username.validate
does not display any component error near the widget.

Is there anything I did not understand about the last part of the sentence: “turned on implicitly if validating the component fails”? Or is it only useful when managing forms through a Form?

Thanks,
Marco

I think the indicator is displayed by the layout containing the component.
Ans that only the Form handles it.

The last part of the sentence is for forms, and as Mathias said, the error indicator is shown by the layout containing the component along with the caption.

Note that in your case, there should not be an error indicator: empty required fields only have the required indicator, no visible error indicator. If any other validation fails, you should get the error indicator.

Thanks Mathias and Henri for your prompt answers,

so I suppose the only way of showing the component error without using Form(s) is by calling it manually: setComponentError(new UserError(…)).

Thanks,
Marco