Directory

← Back

PropertyTranslator

What PropertyFormatter does for TextFields, PropertyTranslator does for Selects

Author

Rating

Popularity

<100

PropertyTranslator is close relative to PropertyFormatter. As where property formatter only works with string based fields (like TextField), PropertyTranslator can be used with any field.

The most apparent use case is with Selects, when identifiers in container datasource and the value in the property datasource don't match.

Note, that PropertyTranslator is very similar to a helper class called PropertyConverter in CustomField add-on. If you already have CustomField in your project, you should use that instead.

Note, that setting property translator for a field in FormFieldFactory is practical since 6.7.3. Form then sets the property to existing property if it implements Property.Viewer interface as the PropertyTranslator does.

Sample code

select.setPropertyDataSource(new PropertyTranslator(beanItemProperty) {
				
				@Override
				public Object translateToDatasource(Object formattedValue) throws Exception {
					// ID -> Entity
					EntityItem<WorkoutType> item = containerDataSource.getItem(formattedValue);
					return item.getEntity();
				}
				
				@Override
				public Object translateFromDatasource(Object value) {
					// Entity -> ID
					WorkoutType wt = (WorkoutType) value;
					return wt == null ? null : wt.getId();
				}
			});

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Fixed some issues with null values.

Released
2011-12-14
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 6.0+
Browser
N/A

PropertyTranslator - Vaadin Add-on Directory

What PropertyFormatter does for TextFields, PropertyTranslator does for Selects PropertyTranslator - Vaadin Add-on Directory
PropertyTranslator is close relative to PropertyFormatter. As where property formatter only works with string based fields (like TextField), PropertyTranslator can be used with any field. The most apparent use case is with Selects, when identifiers in container datasource and the value in the property datasource don't match. Note, that PropertyTranslator is very similar to a helper class called PropertyConverter in CustomField add-on. If you already have CustomField in your project, you should use that instead. Note, that setting property translator for a field in FormFieldFactory is practical since 6.7.3. Form then sets the property to existing property if it implements Property.Viewer interface as the PropertyTranslator does.
Online