Button.clickInClient

In one class I created a button and added a click listener to this button. Now in another class according to some conditions I would like to call the button and make sure that it enters the click listener event. Practically from code I would like to launch the clickListener of the button. Does anyone know how I can do?
I also did “button.clickInClient()” but it doesn’t enter!

Hi! If you have reference to the button from the another class (like getMyButton()), then you can call click() method on it:
getMyButton().click();
This fires the click event and thus the click event listener will be called.
Is this what you need?
Or a another solution could be you make a public (callable from another class) method
public void myButtonEvent(ClickEvent event) { ...}
and call from the button addClickListener
myButton.addClickListener(clickEvent -> myButtonEvent(clickEvent));
and call whereever you want, ie. from the other class, but then you may need the clickEvent param… if your method uses it. If the clickEvent parameter is unimportant, then it’s easy, your external click event method will look like this:
public void myButtonEvent() { ... }
But imho, the first approach is better and easier :wink: