Button click listener with method Listener wrapper

hello,

In vaadin 6, iI used to use this kind of syntax to attach a button click listener to a method :

button_2.addListener(ClickEvent.class,controllerClass,method);

where controllerClass is an instance of my class and method, the name of the method as a string

But I can see that this method is now deprecated with Vaadin 7.

So which kind of solution to replace this would you recommend me ?
I red that there was some ‘methodwrapper’ but I can’t find an example…

Thanks !

You should use instances of ClickListener which can be added using Button#addClickListener(). If you don’t want to write a ClickListener for each action, it should be fairly simple to write one that takes a ControllerClass-instance and a method-name, gets the method via Reflection and calls it.

I see… But I was wondering if there’s not a “pure vaadin” solution ?

Well from my point of view these addListener(Method)-Methods look always more like an implementation-detail that shouldn’t have made into the API in the first place. And as the Vaadin-team is currently cleaning up the API, they might very well removed this. As I didn’t find an equivalent (I didn’t search very much), I guess this way of Handler-registration will be gone in Vaadin 7 in favor of the more explicit but cleaner way of registering anonymous listener-classes.

Indeed, the addListener() version based on reflection should have never made it into the public API. It is not really safe when code is being modified (no compile time check) and was originally intended for internal use only.

Furthermore, as Tobias said, it is easy to create your own little listener class that does this (and maybe even a subclass of the component that provides this API) if you want to use such anyway so not having it in the public API only requires you to write a tiny bit more code that IDEs can mostly auto-generate or auto-complete.