CombBox ValueChangeListener never called

Hi Folks,

I have a ComboBox which I’m trying to get a ValueChangeListener to be called when an item in the box is selected by the user. My ValueChangeListener is never called.

Here’s the ComboBox construction:


ComboBox cb = new ComboBox("Country");
//		cb.setRequired(true);
		cb.setRequiredError("Please select the Country");
		cb.setNullSelectionAllowed(false);

		boolean foundDefault = false;
		// getSet returns a Set<Country> of all Country's
		for (Country c : getSet()) {
		    cb.addItem(c);
		    cb.setItemCaption(c, c.getName());
		    if (defaultCountry != null && foundDefault == false) {
			if (c.getName().equals(defaultCountry.getName())) {
			    System.out.printf("Setting ComboBox default to <%s>\n", c.getName());
			    cb.setValue(c); // "Canada1" appears for value
			    foundDefault = true;
			}
		    }
		}
		//cb.setFilteringMode(Filtering.FILTERINGMODE_OFF);
		// Test to make sure listener works (unrelated to default value issue)
		cb.setImmediate(true);
		cb.addListener(new ValueChangeListener() {
		    public void valueChange(ValueChangeEvent event) {
			System.out.printf("Country ComboBox event\n");
		    }
		});

If I put the above in a stripped down test app (files attached) then valueChange() method is called correctly. However, in my more complex actual application it is never called. I’m not sure how to debug this one. I’ve stepped through the cb.addListener(…) in my application and it looks like the listener is registered properly. I’m not sure how to step through the combobox when it’s selected to see why the listener is not called.

Would really appreciate some suggestions on this one.
12073.java (5.6 KB)
12074.java (3.91 KB)
12075.java (506 Bytes)
12076.java (5.31 KB)
12077.java (8.27 KB)

Hi Folks,

Any thoughts on this one? I wish I could reproduce the problem in a compact enough form to post here. I’m seriously considering hiring a psychic and maybe a witch doctor to help me figure out where the problem is. :slight_smile:

Would love to hear about any similar sounding listener problems you might have seen.

Would also love some advice just on how to debug this problem.

mike

Have you tried changing the value programmatically after you add the listener? It would give you a place to put a breakpoint at least.

Hi,
I hope that you have already solved your problem. In case if not and this is still important for you my proposition is to do the following:


//somwhere in method call
ComboBox cb = new ComboBox();
cb.addItem("1");
cb.addItem("2");
cb.setValue("1");
cb.addListener(ValueChangeEvent.class, this, "valueChange");

//valueChange eventListener
	public void valueChange(ValueChangeEvent event) {
		showNotification("valueChange", Notification.TYPE_HUMANIZED_MESSAGE);
	}