setComponentError within ActionListener

Hi guys!

I’m new to Vaadin and currently working my way trough. Up to now it very much met my expectations I’m thrilled of the possibilities this framework supports!

Though I have small question:

What is the reason that this:

Button testbtn = new Button("test", new Button.ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				setComponentError(new UserError("error"));
			}
		});

won’t display an error on the Button. Is it because I can’t set an Error on the same Component while i am in its constructor?
But the code in the ClickListener is executed after the Button is defined… :confused:

TIA
foerdsch

Hi,

try this:


Button testbtn = new Button("test",new Button.ClickListener() {

    @Override
    public void buttonClick(ClickEvent event) {
        event.getButton().setComponentError(new UserError("error"));
    }
});

or this:


final Button testbtn = new Button("test");
testbtn.addListener(new Button.ClickListener() {

	@Override
	public void buttonClick(ClickEvent event) {
		testbtn.setComponentError(new UserError("error"));
	}
});	

I don’t understand why but that actually did the trick! Thanks a lot! :slight_smile: