VaadinPropertyDescriptor

Looking for the equivalent to Swing TableCellRenderer It seems to me that the best solution would to employ specific properties for specific types. As an example I have an Amount type (currency and values fields) that can be converted from/to strings of type “$ 540.00” or “GBB 180.00”. Apart the intricacies imposed by currency (e .g. no decimals for Yens) the conversion shall consider user locale to properly understand punctuation.

But even once I have an AmountProperty, I can’t understand how to bind it to the bean field. Tapping into the code I see that AbstractBeanContainer uses the
model
field to lookup for VaadinPropertyDescriptor that ate responsible for creating properties. On the other side model is private and used directly (instead of calling a protected getModel()) method. Thus MethodPropertyDescriptors generate all properties as MethodProperties.

Do anybody know a simple way to use my own Properties inside a BeanContainer? The alternative would be to over(re)write lot of Vaadin data API, but I suppose there shall be a better way to address such a common need .

Thanks for any kind of help!

The protected method addContainerProperty(String propertyId, VaadinPropertyDescriptor propertyDescriptor) actually modifies the model so all old and new items will have an instance of your property generated automatically.

Therefore, you should subclass BeanContainer, calling addContainerProperty(“amount”, new AmountPropertyDescriptor()) at the end of your constructor.

Your class AmountPropertyDescriptor implements VaadinPropertyDescriptor { … } should return e.g. String as the type of the property and a new AmountProperty instance as the property itself in your implementation of AmountPropertyDescriptor.

Hi Henri,

Thank you very much for your help. This was in fact my first attempt but since the property is already present (because model has already been populated by parent constructor), but failed because adding a property returns false (the model already contains the key).

Anyway I will try an unorthodox workaround to iterate on model (accessed through reflections since it is private) properties and replace only those VaadinPropertyDescriptors exactly where you suggested (i. e. after a call to super() constructor).

Thanks again,

franco

You could also add the property with a different name and then map the display names elsewhere for presentation - whichever works better for you.