ComboBox not showing default

Hi Folks,

I am having trouble with ComboBox’s in general not showing the default value and would love some advice.

Here’s the combobox constructions:


		ComboBox cb = new ComboBox("Type");
		log.debug(m, "Default <%s> hc=%x", value, value.hashCode());
		cb.setRequired(true);
		cb.setRequiredError("Please select the Type");
		cb.setNullSelectionAllowed(false);
		for (PhoneNumType type : PhoneNumType.VALUES) {
		    if (type.isNOTSET())
			continue;
		    log.debug(m, "Adding PhoneNumType <%s> hc=%x", type, type.hashCode());
		    cb.addItem(type);
		    if (type.getLiteral().equalsIgnoreCase(value.toString())) {
			log.debug(m, "Set default <%s> hc=%x", value, value.hashCode());
			cb.setValue(type);
		    }
		}

The PhoneNumType is an enum and is attached.

When I run this code my debug output shows that “Set default <…>” is called and there-for cb.setValue(type) is being called:


 createField: Default <WORK> hc=64ca9718
 createField: Adding PhoneNumType <WORK> hc=3085dc5a
 createField: Set default <WORK> hc=64ca9718
 createField: Adding PhoneNumType <HOME> hc=2445b199
 createField: Adding PhoneNumType <MOBILE> hc=5b8ec669

Unfortunately the displayed ComboBox shows nothing as selected.

What am I missing here?

mike
12011.java (5.3 KB)

Still stuck on this one. Anybody have any suggestions?

Pretty please?

mike

Nothing particular catches my eye, but I suppose it could be some problem with the itemID type that you use, for example that equals() or something doesn’t work.

I made a
quick test
with ComboBox with enum types and it seems to work OK.

Marco,

Thanks for looking. I just tried this to make this a String based select:


	    Select cb = new Select("Address Type");
	    cb.setDescription("The Type of address");
	    cb.setNullSelectionAllowed(false);
	    for (AddressType type : AddressType.values()) {
		if (type.isNOTSET())
		    continue;
		log.debug(m, "Adding <%s>", type.getName());
		cb.addItem(type.getName());
		if (prop.getValue() != null && prop.getValue().toString().equals(type.getName())) {
		    log.debug(m, "set default <%s>", type.getName());
		    cb.setValue(type.getName());
		}
	    }

The debug output shows setValue being called:


2011-11-04 08:22:28,351 DEBUG [vortex.console.ui.slate.EditorField]
 <62> getField: Adding <Work>
2011-11-04 08:22:28,352 DEBUG [vortex.console.ui.slate.EditorField]
 <62> getField: Adding <Home>
2011-11-04 08:22:28,352 DEBUG [vortex.console.ui.slate.EditorField]
 <62> getField: set default <Home>
2011-11-04 08:22:28,352 DEBUG [vortex.console.ui.slate.EditorField]
 <62> getField: Adding <Other>

Since type.getName() is return String this is no longer a case of it being an enum issue. I also tried using Select instead of ComboBox but the result is the same.

I sure wish ComboBox threw some kind of exception when setValue() is given an argument which is not found or somehow invalid. Just being silent about not using the argument given makes debugging much harder.

mike

Marco,

Forgot to add…

I inserted the “quick test” code from the example book into my App and it does NOT work. It also shows no selected value.

I’m using Vaadin 6.6.8. I’ve tested with Firefox 7 and 3.x.

mike

I’ve found the problem. The bug was deep in the PropertysetItem I was using as the data source for the form which used the ComboBox. Apparantly I “simplified” the example far too much in my posting. :frowning:

I really appreciate your suggestions and feedback!

mike