简体   繁体   中英

Custom converter for primitive type

In my wicket app, I want to use my own converter for some textfields with double (primitive type "double", not "Double" type) values.

I created mij converter and registered it, but only the method convertToString is called (when rendering), not the convertToObject (when submitting). It apparently comes from the fact that my textfield is mapped with a property of primitive type double (because if I change it to Double, then the method convertToObject is called).

Is this behaviour normal ? Is there a way to get my converter to work with a primitive type ? Or do I simply miss something in my understanding of how converters work ?

Thanks in advance.

I think the problem it is the way you are registering the converter, in order to register a converte of TYPE double

ConverterLocator converter= new ConverterLocator();
converter.set(Double.TYPE, DoubleConverter.INSTANCE);

see the source of ConverterLocator.class for more examples :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM