this.addValueChangeListener compile error

Hello

I have created a customised ComboBox as
public class Combo2 extends ComboBox {

I can add other listeners in the constructor e.g.
this.addFocusListener(
… works. When I try to add a value change listener
this.addValueChangeListener(
… NetBeans complains about syntax.

Error on line this.addValueChangeListener:
<anonymous combovaluechangelistener.Combo2$3> is not abstract and does not override abstract method valueChange(ValueChangeEvent) in ValueChangeListener

Error on @Override valueChange():
method does not override or implement a method from a supertype

I have tried moving the addValueChangeListener to attach() or to a separate method without success. I have tried to implement the ValueChangeListener in the class (…extends ComboBox implements ValueChangeListener) overriding the changeValue -method in the class without success. If I let my IDE implement the missing methods, it implements valueChange(…) again and again exactly as I have implemented it in the first place - and it shows an error.

Is this correct? Am I missing something?

Cheers
Keimo



Combo2.java

[font=courier new]
package combovaluechangelistener;

import com.vaadin.data.Property;
import com.vaadin.event.FieldEvents;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Field;
import com.vaadin.ui.Notification;

public class Combo2 extends ComboBox {

public Combo2(String caption) {
    super(caption);

    this.addItem("zh");
    this.addItem("zg");
    this.addItem("gl");

    // adding 2 focus listeners works
    this.addFocusListener(new FieldEvents.FocusListener() {

        @Override
        public void focus(FieldEvents.FocusEvent event) {
            Notification.show("Focus listener 1");
            System.out.println("Focuslistener 1");
        }
    });

    this.addFocusListener(new FieldEvents.FocusListener() {

        @Override
        public void focus(FieldEvents.FocusEvent event) {
            Notification.show("Focus listener 2");
            System.out.println("Focuslistener 2");
        }
    });

    /**/
    // COMPILE ERROR HERE
    this.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Field.ValueChangeEvent event) {
            Notification.show("Value changed");
        }
    });
    /**/
}

}
[/font]



MyVaadinUI.java:

[font=courier new]
package combovaluechangelistener;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.data.Property;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@Theme(“mytheme”)
@SuppressWarnings(“serial”)
public class MyVaadinUI extends UI {

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class, widgetset = "combovaluechangelistener.AppWidgetSet")
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);

    Button button = new Button("Click Me");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            layout.addComponent(new Label("Thank you for clicking"));
        }
    });
    layout.addComponent(button);

    ComboBox cb1 = new ComboBox("combo box 1");
    cb1.addItem("ag");
    cb1.addItem("ai");
    cb1.addItem("ar");

    cb1.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            Notification.show("changed combo box 1");
        }
    });
    layout.addComponent(cb1);

    // create another "custom" combo box
    Combo2 cb2 = new Combo2("combo box 2");
    layout.addComponent(cb2);
    /*        
     cb2.addValueChangeListener(new Property.ValueChangeListener() {

     @Override
     public void valueChange(Property.ValueChangeEvent event) {
     Notification.show("changed combo box 2");
     }
     });
     */

    System.out.println("Listener list 1: " + cb1.getListeners(Property.ValueChangeEvent.class));
    System.out.println("Listener list 2: " + cb2.getListeners(Property.ValueChangeEvent.class));
}

}
[/font]

Hi,

the method declaration in your ValueChangeListener is:
public void valueChange(Field.ValueChangeEvent event)
when it should be:
public void valueChange(Property.ValueChangeEvent event)

Not sure if this is the cause of the problem but it might be.

-tepi

Thank you Teppo. Helped us a lot! The IDE generates the code like that and I did not check it carefully enough.

Keimo