TypedTextField.setDatatype() ignored when using ContainerValueSource

Hi Jmix team,

I’m using Jmix 2.8.2 with TypedTextField<BigDecimal> and a ContainerValueSource.

I need dynamic decimal formatting (2, 5, or 14 decimal places depending on runtime conditions), so I’m assigning a custom datatype programmatically:

textField.setDatatype(adaptiveDatatype);
textField.setValueSource(new ContainerValueSource<>(dc, "defFldNum"));

However, the custom datatype is ignored once the ContainerValueSource is attached. After checking the source, I noticed that convertToPresentation() and convertToModel() always use the entity property’s datatype whenever an EntityValueSource exists, instead of the datatype assigned through setDatatype().

Is this the intended behavior?

If so, what is the recommended approach for applying a runtime/custom datatype while still using ContainerValueSource?

Hi,

Yes, this is intended behavior. When the field is bound to an entity attribute, the attribute’s datatype takes priority, and the datatype set via setDatatype() is silently ignored. It is only used when the component works without entity binding.

There are two recommended approaches for your case:

  1. Remove databinding ContainerValueSource and sync the value between the field and the entity manually.

  2. Subclass TypedTextField and override convertToPresentation() / convertToModel(). In your implementation, let the datatype set via setDatatype() take priority over the entity property’s datatype. Container binding should keep working as usual. See how to override components: Replacing Standard Components :: Jmix Documentation