Correct way to use setComponentError()

Hi,

I wanted to use setComponentError(ErrorMessage componentError) directly from my app. It would be nice to have the same method with a plain string parameter.

However there seems to be UserError in com.itmill.toolkit.terminal package, that implements ErrorMessage

Is it correct to create new UserError and use that?

Yes, below is an example:

    void init_errorTest(final Window main) {
        final TextField textfield = new TextField("Enter name");
        main.addComponent(textfield);
        
        final Button button = new Button("Click me!");
        main.addComponent(button);
        
        button.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                if (((String)textfield.getValue()).length() == 0)
                    textfield.setComponentError(new UserError("Must not be empty"));
                else // Clear the error
                    textfield.setComponentError(null);
            }
        });
    }

This works at least in Toolkit 4. Toolkit 5 seems to have a problem that occurs after the error indicator has been displayed once and cleared.

[quote=Marko Grönroos]
Toolkit 5 seems to have a problem that occurs after the error indicator has been displayed once and cleared.
[/quote] Fixed, will work in the next release.