struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4216) Error in XWorkBasicConverter.convertValue()
Date Fri, 21 Mar 2014 20:51:43 GMT

    [ https://issues.apache.org/jira/browse/WW-4216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13943526#comment-13943526
] 

Lukasz Lenart commented on WW-4216:
-----------------------------------

I found only that https://issues.apache.org/jira/browse/XW-543

> Error in XWorkBasicConverter.convertValue()
> -------------------------------------------
>
>                 Key: WW-4216
>                 URL: https://issues.apache.org/jira/browse/WW-4216
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.15.1
>            Reporter: Harigopal Patel
>             Fix For: 2.3.17
>
>
> if multiple name parameter in action then create string array
> ex :- abc.action?id=4&id=4&name=xyz
> Object value = string array [0=4,1=4]
> Class toType = int
> 2.0.7 branch :- no check Primitive data type
> {code:java}
> public Object convertValue(Map context, Object o, Member member, String s, Object value,
Class toType) {
>         Object result = null;
>         if (value == null || toType.isAssignableFrom(value.getClass())) {
>             return value;
>         }
>         if (toType == String.class) {
>             Class inputType = value.getClass();
>             if (Number.class.isAssignableFrom(inputType)) {
>                 result = doConvertFromNumberToString(context, value, inputType);
>                 if (result != null) {
>                     return result;
>                 }
>             }
>             result = doConvertToString(context, value);
>         } else if (toType == boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType == Boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType.isArray()) {
>             result = doConvertToArray(context, o, member, s, value, toType);
>         } else if (Date.class.isAssignableFrom(toType)) {
>             result = doConvertToDate(context, value, toType);
>         } else if (Collection.class.isAssignableFrom(toType)) {
>             result = doConvertToCollection(context, o, member, s, value, toType);
>         } else if (toType == Character.class) {
>             result = doConvertToCharacter(value);
>         } else if (toType == char.class) {
>             result = doConvertToCharacter(value);
>         } else if (Number.class.isAssignableFrom(toType)) {
>             result = doConvertToNumber(context, value, toType);
>         } else if (toType == Class.class) {
>             result = doConvertToClass(value);
>         }
>         if (result == null) {
>             if (value instanceof Object[]) {
>                 Object[] array = (Object[]) value;
>                 if (array.length >= 1) {
>                     value = array[0]; /************ call this code value = 4 ****************/
>                 }
>                 result = convertValue(context, o, member, s, value, toType);
>             } else if (!"".equals(value)) { // we've already tried the types we know
>                 result = super.convertValue(context, value, toType);
>             }
>             if (result == null && value != null && !"".equals(value))
{
>                 throw new XWorkException("Cannot create type " + toType + " from value
" + value);
>             }
>         }
>         return result;
>     }
> {code}
> 2.1.2 branch :- check Primitive data type
> {code:java}
> public Object convertValue(Map<String, Object> context, Object o, Member member,
String propertyName, Object value, Class toType) {
>         Object result = null;
>         if (value == null || toType.isAssignableFrom(value.getClass())) {
>             return value;
>         }
>         if (toType == String.class) {
>             Class inputType = value.getClass();
>             if (Number.class.isAssignableFrom(inputType)) {
>                 result = doConvertFromNumberToString(context, value, inputType);
>                 if (result != null) {
>                     return result;
>                 }
>             }
>             result = doConvertToString(context, value);
>         } else if (toType == boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType == Boolean.class) {
>             result = doConvertToBoolean(value);
>         } else if (toType.isArray()) {
>             result = doConvertToArray(context, o, member, propertyName, value, toType);
>         } else if (Date.class.isAssignableFrom(toType)) {
>             result = doConvertToDate(context, value, toType);
>         } else if (Calendar.class.isAssignableFrom(toType)) {
>             result = doConvertToCalendar(context, value);
>         } else if (Collection.class.isAssignableFrom(toType)) {
>             result = doConvertToCollection(context, o, member, propertyName, value, toType);
>         } else if (toType == Character.class) {
>             result = doConvertToCharacter(value);
>         } else if (toType == char.class) {
>             result = doConvertToCharacter(value);
>         } else if (Number.class.isAssignableFrom(toType) || toType.isPrimitive()) {
> /************ call this code because toType is a int data type but throws error because
value is a string array[0=4,1=4] ****************/
>             result = doConvertToNumber(context, value, toType);
>         } else if (toType == Class.class) {
>             result = doConvertToClass(value);
>         }
>         if (result == null) {
>             if (value instanceof Object[]) {
>                 Object[] array = (Object[]) value;
>                 if (array.length >= 1) {
>                     value = array[0];
>                 } else {
>                     value = null;
>                 }
>                 result = convertValue(context, o, member, propertyName, value, toType);
>             } else if (!"".equals(value)) { // we've already tried the types we know
>                 result = super.convertValue(context, value, toType);
>             }
>             if (result == null && value != null && !"".equals(value))
{
>                 throw new XWorkException("Cannot create type " + toType + " from value
" + value);
>             }
>         }
>         return result;
>     } 
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message