While using Table.formatPropertValue()
for formatting table columns is a viable option, I strongly discourage from using this method when working with Vaadin 7. formatPropertValue()
is the old Vaadin 6 way of formatting Table values. This method is still available in Vaadin 7 for downward compatibility. Using this method is problematic in several ways:
- It is not typesafe. Since you only get a
Property<?>
as a parameter you first have to check for the concrete type of the property value.
- You have to inherit from Table only to adapt the formatting of one or more columns. Class inheritance is definitely the wrong approach for adapting a class's behavior for one particular use case. If you have more than one such cases, you'll end up implementing a bunch of Table subclasses which later can't be easily interchanged.
- You hard-wire conversion code (BigDecimal to String) to the concrete implementation of some UI component. That's bad for re-use. What if you need that conversion in some other place, say when you display a BigDecimal on a Label? You'd have to duplicate this code or somehow extract it into a separate class or method.
The last point is exactly what Vaadin 7 does for you: keep conversion logic separate from some concrete UI component. This is what the com.vaadin.data.util.converter.Converter
interface is for. So, the OP was quite right in his/her first assumption: Table.setConverter()
is the way to go with Vaadin 7. Converters are typesafe and allow for separation of concerns.
The objection that the Converter which can be set with Table.setConverter()
only converts from BigDecimal to String is not justified in this case. Table.formatPropertValue()
doesn't do anything different - it also converts to String. But this is obvious, a Table doesn't display anything other than String data in its columns. In fact, the default behaviour of Table is to call the toString()
method on Property
value types that it can't convert on its own.
For using Converters, see section 9.2.3 of the Book of Vaadin.