NativeSelect: Caption of the "null item"

Hi,

I’ve set setNullSelectionAllowed(true) for a NativeSelect component. The “null item” shows empty in the UI.

I want the null item to look like “Select” (to give the user a hint).

Is there a way to change caption for the null item? I would really like to avoid hacking my own “null item” only because of the the caption.

I’m working with Vaadin 7 beta8 at the moment.

Br,
Mikko

If you want a custom caption, then you need to have a item for that selection; use setNullSelectionItemId and setItemCaption to accomplish what you want.

Thanks Thomas. I’ve got another question about null selection item caption.

I have set a data source for a NativeSelect instance. I’m confused about how to handle the null selection caption.

When I set a data souce for my NativeSelect and call setNullSelectionAllowed(true) the caption of null item is empty. setNullSelectionItemId+setItemCaption have no affect. If I comment out setContainerDataSource and setItemCaptionPropertyId, the null caption works. The code is below.

Is it really so that setting null caption this way is possible only when there is no data source?


myNativeSelect.setContainerDataSource(myDataSource);
myNativeSelect.setItemCaptionPropertyId("propertyName");
myNativeSelect.setMultiSelect(false);
myNativeSelect.setNullSelectionAllowed(true);
myNativeSelect.setNullSelectionItemId(9999);
myNativeSelect.setItemCaption(9999, "My personal null item caption");

I’m still using Vaadin 7 beta8 (because of some strange Spring integration problems with newer versions).

Mikko

Yeah, i’m having exactly the same problem as you M N. Have you found a way? Plz share if you accomplish it.

Sorry for the slow response. No progress, I just implemented my stuff different way to avoid the problem. I haven’t tried it after updating to Vaadin 7.0.0.