[MGNLUI-6949] Support binding of enumDatasource Created: 15/Nov/21  Updated: 17/Nov/23

Status: Open
Project: Magnolia UI
Component/s: None
Affects Version/s: 6.2.13
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Carlos Cantalapiedra Assignee: Unassigned
Resolution: Unresolved Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
dependency
is depended upon by MGNLUI-7451 SwitchableField that allows EnumDatas... Open
duplicate
is duplicated by MGNLUI-6150 Form is broken when using enumDatasou... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

Actually, if an enumDatasource is used as datasource of a combobox field, the error message: "Linking to enums is not supported" is thrown because the method getDefaultConverter is unimplemented.

For every particular enum that is used as the source of a Datasource, a subtype of EnumSelectFieldSupport has to be implemented providing a #defaultConverter() (so the enum values are converted into a presentation String)

It would be also useful to implement an interface translatableEnum with one method String getTranslationKey() which could be implemented/extended by EnumSelectFieldSupport to get the keys for the translations of enum values.

On some IDEs like IntelliJ, it is needed to include the annotation formatter:off - formatter_on between the implementationClass at the module descriptor regarding significant white spaces, it could be useful to include some java code control like trim for avoiding this issue



 Comments   
Comment by Michiel Meeuwissen [ 10/Jan/22 ]

What is a bit silly too, is that in SelectFieldBinder the code is this:

 

 return Optional.ofNullable(super.createConfiguredConverter(definition, field).orElse((Converter) this.selectFieldSupport.defaultConverter()))

According to javadoc of SelectFieldSupport:

 If FieldDefinition.getConverterClass() is set then defaultConverter is ignored - e.g. for case when field model FieldDefinition.getType() is not String type.

Which seems to be untrue in this case. It is not ignored. It is called.

Even specifying a converterClass doesn't help, because it will simply still call 'defaultConverter', and hence cause mentioned exception.

Comment by Michiel Meeuwissen [ 18/Jan/22 ]

It all seems a bit cumbersome. We ended up constructing something simpler:

https://github.com/vpro/magnolia-vpro-ui#enum_field

Comment by Samuli Saarinen [ 17/Nov/23 ]

Stumbled on this today my self trying to use enumDatasource on a form field leading to mysterious "Linking to enums is not supported" exception. I would call this a bug at least when there is absolutely no documentation, that I could find, stating that enumDatasource is not intended to be used w/ form fields like all the other datasources.

Generated at Mon Feb 12 09:41:37 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.