Vaadin Serializable Listeners

Hello Everyone,

I have a question that I didn’t find the answer in the documentation. Sorry for my poor english.

All Vaadin component listeners that I know are serializable. Why?

The reason I ask this is because what we normally do with listeners is something like this:

public class VaadinPage extends HorizontalLayout {
    private final Button leButton;
    public VaadinPage() {
         leButton = new Button(); 
         leButton.addListener(new Button.ClickListener() {
              public void buttonClick(ClickEvent event) {
                     // do something.

I.e., we create an anonymous inner class of Button.ClickListener to do something related to the UI/Model based on the button click. The problem is that this anonymous class is serializable, and because it’s anonymous, it has a reference to the instance that created it. Consequently, it will try to serialize the instance that it references too. This is a known findbug bug (
). A basic solution is transforming the anonymous inner class in a nested class, but this is not always possible/desired.

So, why are all listeners serializable? Do you think this findbug bug should be ignored when using vaadin? If yes, why?

Hope someone can help me with this question :slight_smile:

Kind Regards, Ralf

All Vaadin components implement Serializable, not just the listeners, if I remember correctly. This is because some special servlet containers like Google App Engine (GAE) requires that the applciation is serializable, so that it can move it from server to server. The downside with it is that every time you do a class that extends anything will nag that you have to have a serialization id in the class and whatnot. Haven’t had much problems with it, but still add the serialization there so that eclipse doesn’t nag to me about it. Apache Tomcat also throws serialization exceptions on startup/shutdown, but that can be fixed by turning off serialization of sessions in the configuration.

Interesting, didn’t know that. Thanks for the answer :slight_smile:

what is the best practise using vaadin components which are all byDefault serializable? Should we suppress warnings or add default serialversionUID ?

ususally classes are made serializable only when required.