struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Prasanth Pasala <ppas...@pangburngroup.com>
Subject Re: Invalid Field Value when using Map
Date Mon, 24 Jun 2019 16:21:01 GMT
I have built a test project to just test the Map variables. In the validate method it does
give a String object (for value of map). But seems like a field error is also added. If I
try to use the map 
in validate method I would get a class cast exception, but if I don't do anything with the
map values then the input page is displayed with invalid field value error.

So I guess the issue is that my validate method is trying to validate the values in the map
and that causes the exception, as the map has String values in it.

I have to update the validation methods to check if the value is of type Double or not. Is
this how it is supposed to work? I would have thought that a field error would be added and
the String value 
would not be added to the Map as the code is expecting Doubles.

Thanks,
Prasanth

On 6/24/19 1:42 AM, Yasser Zamani wrote:
> Hi,
>
> I think putting breakpoints at [1] and [2] and seeing if you reach there and what happens
next can help proceeding this issue.
>
> Thanks in advance!
>
> Regards.
>
> [1] https://github.com/apache/struts/blob/651eac2c57396aa11ee65002006b3123dd69cbb4/core/src/main/java/com/opensymphony/xwork2/conversion/impl/DefaultObjectTypeDeterminer.java#L114
> [2] https://github.com/apache/struts/blob/651eac2c57396aa11ee65002006b3123dd69cbb4/core/src/main/java/com/opensymphony/xwork2/interceptor/ConversionErrorInterceptor.java#L118
>
>
>> -----Original Message-----
>> From: Prasanth <dbadmin@pangburngroup.com>
>> Sent: Friday, June 21, 2019 6:27 PM
>> To: user@struts.apache.org
>> Subject: Re: Invalid Field Value when using Map
>>
>> Hi Yasser,
>>
>> The conversion error occurs when the field is not a map. I have a form with
>> int/long fields, if the user enters non numeric value the form display error.
>>
>> The actions are validation aware and the control does come to validation
>> method. It is in the validation method that I usually get exceptions  as the code
is
>> expecting to have a Double but the type of the object in the map is a String. I
>> have tried to check in the validate method if the object is of type Double and if
it
>> is not a Double add a field error. When I do that OGNL seems to have an issue
>> when displaying the input form with the values in the map. Seems like OGNL is
>> now expecting a Double value and is not able to handle a String object being
>> present in the map. The JSP stops at the field which has String value.
>>
>> So even if I add additional validations to make sure all values in the map are
>> Doubles it would still cause a problem as Struts would not be able to display the
>> input form.
>>
>> Thanks,
>> Prasanth
>>
>> On 6/21/19 1:23 AM, Yasser Zamani wrote:
>>> Oh interesting!
>>>
>>> Have you seen [1]? e.g. conversion error interceptor should be present
>>> in your interceptor stack. To debug, for example put a number field
>>> which is not a map and see if conversion error appears - I think you
>>> should also have fieldErrors tag in your jsp.
>>>
>>> It seems your action also should be ValidationAware. Put a break-point
>>> at [2] and see if your code reaches there and what happens next.
>>>
>>> Regards.
>>>
>>> [1]
>>> https://struts.apache.org/core-developers/type-conversion.html#collect
>>> ion-and-map-support
>>> [2]
>>> https://github.com/apache/struts/blob/651eac2c57396aa11ee65002006b3123
>>>
>> dd69cbb4/core/src/main/java/com/opensymphony/xwork2/interceptor/Conver
>>> sionErrorInterceptor.java#L116
>>>
>>> On 6/19/2019 10:35 PM, Prasanth Pasala wrote:
>>>> Hi Yasser,
>>>>
>>>> I think at run time you can add any type of objects you want to the map.
>>>> The checks are only at compile time on the data types of objects
>>>> added to Maps.
>>>>
>>>> Thanks,
>>>> Prasanth
>>>>
>>>> On 6/19/19 1:29 AM, Yasser Zamani wrote:
>>>>> Hi Prasanth,
>>>>>
>>>>> I'm surprised how you get non digit characters in your map while
>>>>> both key and value are not String!
>>>>>
>>>>> Regards.
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Prasanth <dbadmin@pangburngroup.com>
>>>>>> Sent: Monday, June 17, 2019 8:52 PM
>>>>>> To: Struts Users Mailing List <user@struts.apache.org>
>>>>>> Subject: Invalid Field Value when using Map
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I have a form that uses maps to store data as shown below. When the
>>>>>> user enters valid numbers it works as expected, but when user
>>>>>> enters non digit characters in the text field a String object is
>>>>>> saved in the map rather than showing a "Invalid field value for
>>>>>> field <field name>" message which is done for basic data types
like
>>>>>> int/long/double. Is this something that struts has not implemented
>>>>>> for maps yet, as the annotations provide the expected data type?
>>>>>>
>>>>>>        @Element(value=java.lang.Double.class)
>>>>>>        private HashMap<Long, Double> deferralAmountValue
= new
>>>>>> HashMap<Long,Double>();
>>>>>>        @Element(value=java.lang.Double.class)
>>>>>>        private HashMap<Long, Double> deferralPercentValue
= new
>>>>>> HashMap<Long,Double>();
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Prasanth
>>>>> --------------------------------------------------------------------
>>>>> - To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


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