Proposal for a nice caption handling for select options

Hi
I think how to configure whats getting displayed of an option in a select box is a bit complicated, proprietary and
doesnt fit in my case. I just wanted to display a value of the property behind an select option.
I think it would be easier to work with and more obvious to understand if a caption could be rendered like that:


Select select = new Select();
select.setContainerDataSource(new BeanItemContainer(pojo));
select.setOptionCaptionMaker(new Select.OptionCaptionMaker(
    public String captionFrom(Property property) {
        return ((PojoClass) property).getMoleculeWeight();
    }
));

Greets
Stefan

Hi,

Perhaps I’m biased, but in this case I think this is pretty simple:

Select select = new Select();
select.setContainerDataSource(new BeanItemContainer(pojo));
select.setItemCaptionPropertyId("moleculeWeight");

Unless I misunderstood the case again… :blink:

Having a callback for this, as in your example, would of course be very flexible, though you’d probably want to get it from the Item, not the Property.

Best Regards,
Marc

Yo you’re right. My simple case is totally covered with the defaults.
The thing with the callback is that I can immediately see what will happen when I look at my code.
For me as a vaadin starter names like ItemCaptionPropertyId are confusing sometimes. Then there are several caption modes making the thing even more complicated.
Vaadin is cool but i wont spent the rest of my days with it so i prefer to write my own code instead of first learning the framework specific vocabulary and then use these new verbs to configure the framworks objects. :lol:
But the more i learn about vaadin the more i like it.

Cheers
Stefan