Application Framework
Linkki Converter Registry
Typically, each UI component is designed to handle a specific data type. However, with the LinkkiConverterRegistry in linkki, developers can customize conversions between model data types and presentation types. This feature expands the capabilities of UI components to support a broader range of value types beyond their defaults.
Default Converters in LinkkiConverterRegistry
Following converters are registered by default in the LinkkiConverterRegistry
:
Converter | Description |
---|---|
|
Calculates the number of milliseconds since |
|
Calculates the number on milliseconds since |
|
Converts |
|
Converts |
|
Converts |
|
Converts |
|
Converts a |
|
Converts a |
|
Convert a |
|
Converts a |
|
Converts a |
|
Converts a |
|
Converts a |
|
Converts a |
|
Converts |
Custom date formats
Custom date formats for a specific Locale
or language code can be registered with DateFormats#register(…)
.
All converters that come with linkki respect these formats.
It is recommended to also respect these date formats in custom converters.
Custom converters
It possible to use custom converters in linkki, e.g. for data types that are not handled by default, or to change the conversion of a certain data type.
Implementing custom converters
All converters must implement the interface Converter<Presentation, Model>
. PRESENTATION
is the type needed by the UI component and MODEL
is the type in the PMO. This interface defines two methods to converter between the two types.
When converting to model, it is possible to check the validity of the input before the value is pushed to the PMO. This can be achieved by returning an error in the result of convertToModel
. In this case, an error message is shown in the UI indicating that the input is not valid. The value of the UI component is restored to its previous value.
Registering custom converters
The converter registry is defined in the Application Configuration.
By implementing ApplicationConfig#getConverterRegistry()
additional custom converters can be registered.
If the registry is initiated with a custom converter which has the same types as an existing one, the custom converter is used with higher priority.