IntegerField: Show defaultValue after clear button is pressed

I have a domain model with an int field (not null) that has a defaultValue that is not 0. Say I display it with the IntegerField in a form. If the user clicks the clear() button, I would like the field to display the defaultValue instead of a blank.

(My actual implementation is an “IntegerNumericField” that subclasses CustomField and wraps a TextField. But I believe that is irrelevant to the issue.)

I cannot find a way to do this using the Binder framework. The BinderBuilder.withNullRepresentation() is close but it solves the reverse problem: What to tell the model when the user clicks clear().

A Converter that replaces nulls with the defaultValue does not work because clear() calls setPresentationValue directly without consulting the Converter chain.

And there is no way for a widget to ask the Binder to refresh the model getter.

I have a way to solve it in my situation: I just store the defaultValue in the CustomField and override the setPresentationValue to replace nulls. But the IntegerField has no solution, afaik.

Did I miss some capability in the Binding framework or is this just a case that has not been considered?

My simple solution would be: don’t use the build-in clear button - build your own where you can supply the correct value.