简体   繁体   English

原始类型的自定义转换器

[英]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. 在我的wicket应用程序中,我想将自己的转换器用于一些具有双(原始类型“双”,而不是“双”类型)值的文本字段。

I created mij converter and registered it, but only the method convertToString is called (when rendering), not the convertToObject (when submitting). 我创建了mij转换器并注册了它,但只调用了convertToString方法(渲染时),而不是convertToObject(提交时)。 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). 它显然来自于我的textfield使用基本类型double的属性映射的事实(因为如果我将其更改为Double,则调用convertToObject方法)。

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 我认为问题在于你注册转换器的方式,以便注册一个TYPE双转换器

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

see the source of ConverterLocator.class for more examples :) 有关更多示例,请参阅ConverterLocator.class的源代码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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