? WW-1112-2.patch ? WW-1112.patch Index: java/com/opensymphony/xwork/util/XWorkBasicConverter.java =================================================================== RCS file: /cvs/xwork/src/java/com/opensymphony/xwork/util/XWorkBasicConverter.java,v retrieving revision 1.29 diff -u -r1.29 XWorkBasicConverter.java --- java/com/opensymphony/xwork/util/XWorkBasicConverter.java 25 Jan 2006 13:05:01 -0000 1.29 +++ java/com/opensymphony/xwork/util/XWorkBasicConverter.java 26 Jan 2006 07:36:01 -0000 @@ -13,47 +13,27 @@ import java.lang.reflect.Array; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; import java.math.BigDecimal; import java.math.BigInteger; -import java.sql.Timestamp; import java.text.DateFormat; import java.text.NumberFormat; import java.text.ParseException; +import java.text.ParsePosition; import java.util.*; /** - * - *

- * WebWork will automatically handle the most common type conversion for you. This includes support for converting to - * and from Strings for each of the following: - *

- *

- *

+ *

WebWork will automatically handle the most common type conversion for you. This + * includes support for converting to and from Strings for each of the following:

*

Note that with arrays the type conversion will defer to the type of the array elements and try to convert each * item individually. As with any other type conversion, if the conversion can't be performed the standard type - * conversion error reporting is used to indicate a problem occured while processing the type conversion. - *

- * + * conversion error reporting is used to indicate a problem occured while processing the type conversion.

* * @author Pat Lightbody * @author Mike Mosiewicz @@ -102,9 +82,11 @@ // let's try to convert the first element only result = convertValue(context, o, member, s, value, toType); } else { - result = super.convertValue(context, value, toType); + if (!"".equals(value)) { + result = super.convertValue(context, value, toType); + } } - + if (result == null && value != null && !"".equals(value)) { throw new XworkException("Cannot create type " + toType + " from value " + value); } @@ -307,14 +289,17 @@ } else if (toType == BigInteger.class) { return new BigInteger((String) value); } else { + String valueString = (String) value; NumberFormat numFormat = NumberFormat.getInstance(getLocale(context)); + ParsePosition parsePosition = new ParsePosition(0); + Number result = numFormat.parse(valueString, parsePosition); - try { - // convert it to a Number - value = super.convertValue(context, numFormat.parse((String) value), toType); - } catch (ParseException ex) { - throw new XworkException("Could not parse number", ex); + if (parsePosition.getIndex() != valueString.length()) { + throw new XworkException("Could not parse number"); } + + // convert it to a Number + value = super.convertValue(context, result, toType); } } else if (value instanceof Object[]) { Object[] objArray = (Object[]) value;