struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Prasanth <>
Subject Re: Map backed form
Date Wed, 06 Mar 2019 16:06:42 GMT
I have created the below in (action class is CompDeferralAction).
The variable name is deferralCode. But still struts is populating the value as Long rather
than Integer. Am I missing anything here?
This action is ModelDriven so the deferralCode variable is in a different class.

Looking at the documentation seems like it should be KeyProperty, so I named it as such.

I have also tried the annotations

    @TypeConversion(rule=ConversionRule.MAP, key="java.lang.Long", value="java.lang.Integer")
    public void setDeferralCode(HashMap<Long, Integer> deferralCode) {
        this.deferralCode = deferralCode;


On 2/16/19 3:20 AM, Yasser Zamani wrote:
> I think a file named beside your action with following
contents should help [1]:
> Key_xxx=java.lang.Long
> Element_xxx=java.lang.Double
> (where xxx is the field name of the collection property in your action or object)
> Regards.
> [1]
>> -----Original Message-----
>> From: Prasanth <>
>> Sent: Friday, February 15, 2019 9:08 PM
>> To:
>> Subject: Re: Map backed form
>> Does struts follow a specific logic as to what the data type of the object would
>> based on user input? Meaning when is it converted to a Double vs Integer vs
>> String?
>> Thanks,
>> Prasanth
>> On 2/15/19 7:45 AM, Lukasz Lenart wrote:
>>> pt., 15 lut 2019 o 00:17 Prasanth <> napisał(a):
>>>> I have a map (Map<Long, Double>) but based on the data entered by the
>>>> user the value in the Map is Double or String. Example if the user enters
>> value of 10 then it is coming in as double but if the user enters 10.5 then a string
>> is present in the value. Does Struts2 look at the data types of the key and value
>> the map and set the key and values in the map accordingly?
>>> Struts is not a problem here, generic types are erased at runtime, so
>>> basically this a Map<Object, Object> at the end
>>>> If not, what is the best practice for the declaration of Map, is there a
way to
>> force Struts2 to only have Double objects as values?
>>> I would probably use a custom type instead of Double and implement
>>> converter for it, or even replace the Map with a List of custom
>>> objects.
>>> Regards
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message