You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andreas Sachs <an...@gmx.de> on 2015/02/22 18:06:46 UTC
Overwrite a TypeConverter for a Map with Generics
Hello,
how can i overwrite a TypeConverter for a Map?
I defined the following global TypeConverter:
java.lang.String=de.xxxx.converter.StringTrimConverter
(the converter removes blanks from the string)
This converter is used for every String, even inside maps. That's fine.
In one action i use the following map:
Map<String, String> textfield = ...
How can i use the default/another String converter for this property?
Using a properties file for the action doesn't work. The Entry "Element_textfield" is not used because i use Generics.
Thanks
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Aw: Re: Overwrite a TypeConverter for a Map with Generics
Posted by Christoph Nenning <Ch...@lex-com.net>.
> Hello,
> thanks for your answer. Have you tried your solution and got it
> working? I already tried that before, but it always picked up the
> global converter de.xxxx.converter.StringTrimConverter. But maybe i
> did something wrong.
>
> I tried it with @TypeConversion(rule = ConversionRule.MAP, converter
> = "de.converter...") (with annotations and also with a class-
> specific conversion-properties file).
>
> If a specify a class name that does not exists, i get an exception.
> But if i use a class that exists, that class is not used for conversion.
>
> I tried to debug DefaultObjectTypeDeterminer: it's looking for an
> @Element annotation. The class-specific properties file
> (Element_textfield) will only be used if i don't use generics.
>
> Or do i need to implement a Map-Converter instead of a String-Converter?
>
> Thanks
> Andreas
>
>
Well, I did not use it for collection types. So you can try with a
MapConverter. And I think those converters are used for saving only, not
for rendering html. Try to annotate the getter, too.
Regards,
Christoph
This Email was scanned by Sophos Anti Virus
Aw: Re: Overwrite a TypeConverter for a Map with Generics
Posted by Andreas Sachs <an...@gmx.de>.
Hello,
thanks for your answer. Have you tried your solution and got it working? I already tried that before, but it always picked up the global converter de.xxxx.converter.StringTrimConverter. But maybe i did something wrong.
I tried it with @TypeConversion(rule = ConversionRule.MAP, converter = "de.converter...") (with annotations and also with a class-specific conversion-properties file).
If a specify a class name that does not exists, i get an exception. But if i use a class that exists, that class is not used for conversion.
I tried to debug DefaultObjectTypeDeterminer: it's looking for an @Element annotation. The class-specific properties file (Element_textfield) will only be used if i don't use generics.
Or do i need to implement a Map-Converter instead of a String-Converter?
Thanks
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Overwrite a TypeConverter for a Map with Generics
Posted by Christoph Nenning <Ch...@lex-com.net>.
> Hello,
> how can i overwrite a TypeConverter for a Map?
>
> I defined the following global TypeConverter:
> java.lang.String=de.xxxx.converter.StringTrimConverter
> (the converter removes blanks from the string)
>
> This converter is used for every String, even inside maps. That's fine.
>
> In one action i use the following map:
> Map<String, String> textfield = ...
> How can i use the default/another String converter for this property?
> Using a properties file for the action doesn't work. The Entry
> "Element_textfield" is not used because i use Generics.
>
> Thanks
> Andreas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
You can annotate the setter for that field, e.g.:
@TypeConversion(converter = "my.package.TextfieldConverter")
public void setTextfield(Map<String, String> textfield)
and of course you have to implement your own converter:
public class TextfieldConverter extends StrutsTypeConverter
regards,
Christoph
This Email was scanned by Sophos Anti Virus