Commits

Anonymous committed b7bb9fc

Fixing type conversions issues:
XWorkBasicConverter now throws a TypeConversionException if the value is not converted
XworkConverter only sets field errors if there is an error, not for null conversion
field errors are set using the value stack, so if the top object is not ValidationAware, this will not lose error messages

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@63e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits cd12e6e

Comments (0)

Files changed (4)

File src/java/com/opensymphony/xwork/XWorkBasicConverter.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork;
-
-import com.opensymphony.util.TextUtils;
-import ognl.DefaultTypeConverter;
-
-import java.lang.reflect.Member;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-
-/**
- *
- *
- * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
- * @author $Author$
- * @version $Revision$
- */
-public class XWorkBasicConverter extends DefaultTypeConverter {
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public Object convertValue(Map context, Object o, Member member, String s, Object value, Class toType) {
-        Object result = null;
-
-        if (toType == String.class) {
-            result = doConvertToString(context, value);
-        } else if (toType == boolean.class) {
-            result = doConvertToBoolean(context, value);
-        } else if (toType == Boolean.class) {
-            result = doConvertToBoolean(context, value);
-        } else if (toType == boolean[].class) {
-            result = doConvertToBoolArray(context, value);
-        } else if (toType == Boolean[].class) {
-            result = doConvertToBooleanArray(context, value);
-        } else if (toType == int[].class) {
-            result = doConvertToIntArray(context, value);
-        } else if (toType == Integer[].class) {
-            result = doConvertToIntegerArray(context, value);
-        } else if (toType == long[].class) {
-            result = doConvertToLongArray(context, value);
-        } else if (toType == Long[].class) {
-            result = doConvertToLongArray2(context, value);
-        } else if (toType == double[].class) {
-            result = doConvertToDoubleArray(context, value);
-        } else if (toType == Double[].class) {
-            result = doConvertToDoubleArray2(context, value);
-        } else if (toType == float[].class) {
-            result = doConvertToFloatArray(context, value);
-        } else if (toType == Float[].class) {
-            result = doConvertToFloatArray2(context, value);
-        } else if (toType == Date.class) {
-            result = doConvertToDate(context, value);
-        } else if (toType == List.class) {
-            result = doConvertToList(context, value);
-        } else if (toType == Set.class) {
-            result = doConvertToSet(context, value);
-        } else if (toType == Collection.class) {
-            result = doConvertToList(context, value);
-        } else if (toType == Class.class) {
-            result = doConvertToClass(context, value);
-        } else {
-            if ((toType == String[].class) && (value instanceof String)) {
-                result = new String[]{(String) value};
-            }
-        }
-
-        if (result == null) {
-            if (value instanceof String[]) {
-                String[] array = (String[]) value;
-
-                if ((array != null) && (array.length == 1)) {
-                    value = array[0];
-                }
-
-                // let's try to convert the first element only
-                result = convertValue(context, value, toType);
-            } else {
-                result = super.convertValue(context, value, toType);
-            }
-        }
-
-        return result;
-    }
-
-    private Object doConvertToBoolArray(Map context, Object value) {
-        boolean[] result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            boolean[] ba = new boolean[sa.length];
-
-            for (int i = 0; i < sa.length; i++) {
-                ba[i] = ((Boolean) doConvertToBoolean(context, sa[i])).booleanValue();
-            }
-
-            result = ba;
-        }
-
-        return result;
-    }
-
-    private Object doConvertToBoolean(Map context, Object value) {
-        if (value instanceof String) {
-            String bStr = (String) value;
-
-            return Boolean.valueOf(bStr);
-        }
-
-        return null;
-    }
-
-    private Object doConvertToBooleanArray(Map context, Object value) {
-        Boolean[] result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            Boolean[] ba = new Boolean[sa.length];
-
-            for (int i = 0; i < sa.length; i++) {
-                ba[i] = ((Boolean) doConvertToBoolean(context, sa[i]));
-            }
-
-            result = ba;
-        }
-
-        return result;
-    }
-
-    private Class doConvertToClass(Map context, Object value) {
-        Class clazz = null;
-
-        if (value instanceof String) {
-            try {
-                clazz = Class.forName((String) value);
-            } catch (ClassNotFoundException e) {
-            }
-        }
-
-        return clazz;
-    }
-
-    private Date doConvertToDate(Map context, Object value) {
-        Date result = null;
-
-        if (value instanceof String) {
-            String sa = (String) value;
-            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
-
-            try {
-                result = sdf.parse(sa);
-            } catch (ParseException e) {
-            }
-        }
-
-        return result;
-    }
-
-    private double[] doConvertToDoubleArray(Map context, Object value) {
-        double[] result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            double[] da = new double[sa.length];
-
-            for (int i = 0; i < sa.length; i++) {
-                da[i] = ((Double) super.convertValue(context, sa[i], Double.class)).doubleValue();
-            }
-
-            result = da;
-        }
-
-        return result;
-    }
-
-    private Double[] doConvertToDoubleArray2(Map context, Object value) {
-        double[] primitives = doConvertToDoubleArray(context, value);
-        Double[] result = null;
-
-        if (primitives != null) {
-            result = new Double[primitives.length];
-
-            for (int i = 0; i < primitives.length; i++) {
-                double primitive = primitives[i];
-                result[i] = new Double(primitive);
-            }
-        }
-
-        return result;
-    }
-
-    private float[] doConvertToFloatArray(Map context, Object value) {
-        float[] result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            float[] da = new float[sa.length];
-
-            for (int i = 0; i < sa.length; i++) {
-                da[i] = ((Float) super.convertValue(context, sa[i], Float.class)).floatValue();
-            }
-
-            result = da;
-        }
-
-        return result;
-    }
-
-    private Float[] doConvertToFloatArray2(Map context, Object value) {
-        float[] primitives = doConvertToFloatArray(context, value);
-        Float[] result = null;
-
-        if (primitives != null) {
-            result = new Float[primitives.length];
-
-            for (int i = 0; i < primitives.length; i++) {
-                float primitive = primitives[i];
-                result[i] = new Float(primitive);
-            }
-        }
-
-        return result;
-    }
-
-    private int[] doConvertToIntArray(Map context, Object value) {
-        int[] result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            int[] ia = new int[sa.length];
-
-            for (int i = 0; i < sa.length; i++) {
-                ia[i] = ((Integer) super.convertValue(context, sa[i], Integer.class)).intValue();
-            }
-
-            result = ia;
-        }
-
-        return result;
-    }
-
-    private Integer[] doConvertToIntegerArray(Map context, Object value) {
-        int[] primitives = doConvertToIntArray(context, value);
-        Integer[] result = null;
-
-        if (primitives != null) {
-            result = new Integer[primitives.length];
-
-            for (int i = 0; i < primitives.length; i++) {
-                int primitive = primitives[i];
-                result[i] = new Integer(primitive);
-            }
-        }
-
-        return result;
-    }
-
-    private List doConvertToList(Map context, Object value) {
-        List result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            result = new ArrayList(sa.length);
-
-            for (int i = 0; i < sa.length; i++) {
-                String s = sa[i];
-                result.add(s);
-            }
-        }
-
-        return result;
-    }
-
-    private long[] doConvertToLongArray(Map context, Object value) {
-        long[] result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            long[] la = new long[sa.length];
-
-            for (int i = 0; i < sa.length; i++) {
-                la[i] = ((Long) super.convertValue(context, sa[i], Long.class)).longValue();
-            }
-
-            result = la;
-        }
-
-        return result;
-    }
-
-    private Long[] doConvertToLongArray2(Map context, Object value) {
-        long[] primitives = doConvertToLongArray(context, value);
-        Long[] result = null;
-
-        if (primitives != null) {
-            result = new Long[primitives.length];
-
-            for (int i = 0; i < primitives.length; i++) {
-                long primitive = primitives[i];
-                result[i] = new Long(primitive);
-            }
-        }
-
-        return result;
-    }
-
-    private Object doConvertToSet(Map context, Object value) {
-        Set result = null;
-
-        if (value instanceof String[]) {
-            String[] sa = (String[]) value;
-            result = new HashSet(sa.length);
-
-            for (int i = 0; i < sa.length; i++) {
-                String s = sa[i];
-                result.add(s);
-            }
-        }
-
-        return result;
-    }
-
-    private String doConvertToString(Map context, Object value) {
-        String result = null;
-
-        if (value instanceof int[]) {
-            int[] x = (int[]) value;
-            List intArray = new ArrayList(x.length);
-
-            for (int i = 0; i < x.length; i++) {
-                intArray.add(new Integer(x[i]));
-            }
-
-            result = TextUtils.join(", ", intArray);
-        } else if (value instanceof long[]) {
-            long[] x = (long[]) value;
-            List intArray = new ArrayList(x.length);
-
-            for (int i = 0; i < x.length; i++) {
-                intArray.add(new Long(x[i]));
-            }
-
-            result = TextUtils.join(", ", intArray);
-        } else if (value instanceof double[]) {
-            double[] x = (double[]) value;
-            List intArray = new ArrayList(x.length);
-
-            for (int i = 0; i < x.length; i++) {
-                intArray.add(new Double(x[i]));
-            }
-
-            result = TextUtils.join(", ", intArray);
-        } else if (value instanceof boolean[]) {
-            boolean[] x = (boolean[]) value;
-            List intArray = new ArrayList(x.length);
-
-            for (int i = 0; i < x.length; i++) {
-                intArray.add(new Boolean(x[i]));
-            }
-
-            result = TextUtils.join(", ", intArray);
-        } else if (value instanceof Date) {
-            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
-            result = sdf.format(value);
-        } else if (value instanceof String[]) {
-            result = TextUtils.join(", ", (String[]) value);
-        }
-
-        return result;
-    }
-}

File src/java/com/opensymphony/xwork/util/TypeConversionException.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.util;
+
+import com.opensymphony.xwork.XworkException;
+
+
+/**
+ * TypeConversionException should be thrown by any TypeConverters which fail to convert values
+ * @author Jason Carreira
+ * Created Oct 3, 2003 12:18:33 AM
+ */
+public class TypeConversionException extends XworkException {
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    /**
+     * Constructs a <code>XworkException</code> with no detail  message.
+     */
+    public TypeConversionException() {
+    }
+
+    /**
+     * Constructs a <code>XworkException</code> with the specified
+     * detail message.
+     *
+     * @param   s   the detail message.
+     */
+    public TypeConversionException(String s) {
+        super(s);
+    }
+
+    /**
+     * Constructs a <code>XworkException</code> with no detail  message.
+     */
+    public TypeConversionException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Constructs a <code>XworkException</code> with the specified
+     * detail message.
+     *
+     * @param   s   the detail message.
+     */
+    public TypeConversionException(String s, Throwable cause) {
+        super(s, cause);
+    }
+}

File src/java/com/opensymphony/xwork/util/XWorkBasicConverter.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.util;
+
+import com.opensymphony.util.TextUtils;
+
+import ognl.DefaultTypeConverter;
+
+import java.lang.reflect.Member;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import java.util.*;
+
+
+/**
+ *
+ *
+ * @author <a href="mailto:plightbo@cisco.com">Pat Lightbody</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+public class XWorkBasicConverter extends DefaultTypeConverter {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public Object convertValue(Map context, Object o, Member member, String s, Object value, Class toType) {
+        Object result = null;
+
+        if (toType == String.class) {
+            result = doConvertToString(context, value);
+        } else if (toType == boolean.class) {
+            result = doConvertToBoolean(context, value);
+        } else if (toType == Boolean.class) {
+            result = doConvertToBoolean(context, value);
+        } else if (toType == boolean[].class) {
+            result = doConvertToBoolArray(context, value);
+        } else if (toType == Boolean[].class) {
+            result = doConvertToBooleanArray(context, value);
+        } else if (toType == int[].class) {
+            result = doConvertToIntArray(context, value);
+        } else if (toType == Integer[].class) {
+            result = doConvertToIntegerArray(context, value);
+        } else if (toType == long[].class) {
+            result = doConvertToLongArray(context, value);
+        } else if (toType == Long[].class) {
+            result = doConvertToLongArray2(context, value);
+        } else if (toType == double[].class) {
+            result = doConvertToDoubleArray(context, value);
+        } else if (toType == Double[].class) {
+            result = doConvertToDoubleArray2(context, value);
+        } else if (toType == float[].class) {
+            result = doConvertToFloatArray(context, value);
+        } else if (toType == Float[].class) {
+            result = doConvertToFloatArray2(context, value);
+        } else if (toType == Date.class) {
+            result = doConvertToDate(context, value);
+        } else if (toType == List.class) {
+            result = doConvertToList(context, value);
+        } else if (toType == Set.class) {
+            result = doConvertToSet(context, value);
+        } else if (toType == Collection.class) {
+            result = doConvertToList(context, value);
+        } else if (toType == Class.class) {
+            result = doConvertToClass(context, value);
+        } else {
+            if ((toType == String[].class) && (value instanceof String)) {
+                result = new String[] {(String) value};
+            }
+        }
+
+        if (result == null) {
+            if (value instanceof String[]) {
+                String[] array = (String[]) value;
+
+                if ((array != null) && (array.length == 1)) {
+                    value = array[0];
+                }
+
+                // let's try to convert the first element only
+                result = this.convertValue(context, o, member, s, value, toType);
+            } else {
+                result = super.convertValue(context, value, toType);
+            }
+        }
+
+        if (result == null) {
+            throw new TypeConversionException("Unable to convert value '" + value + "' to type " + toType.getName());
+        }
+
+        return result;
+    }
+
+    private Object doConvertToBoolArray(Map context, Object value) {
+        boolean[] result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            boolean[] ba = new boolean[sa.length];
+
+            for (int i = 0; i < sa.length; i++) {
+                ba[i] = ((Boolean) doConvertToBoolean(context, sa[i])).booleanValue();
+            }
+
+            result = ba;
+        }
+
+        return result;
+    }
+
+    private Object doConvertToBoolean(Map context, Object value) {
+        if (value instanceof String) {
+            String bStr = (String) value;
+
+            return Boolean.valueOf(bStr);
+        }
+
+        return null;
+    }
+
+    private Object doConvertToBooleanArray(Map context, Object value) {
+        Boolean[] result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            Boolean[] ba = new Boolean[sa.length];
+
+            for (int i = 0; i < sa.length; i++) {
+                ba[i] = ((Boolean) doConvertToBoolean(context, sa[i]));
+            }
+
+            result = ba;
+        }
+
+        return result;
+    }
+
+    private Class doConvertToClass(Map context, Object value) {
+        Class clazz = null;
+
+        if (value instanceof String) {
+            try {
+                clazz = Class.forName((String) value);
+            } catch (ClassNotFoundException e) {
+            }
+        }
+
+        return clazz;
+    }
+
+    private Date doConvertToDate(Map context, Object value) {
+        Date result = null;
+
+        if (value instanceof String) {
+            String sa = (String) value;
+            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
+
+            try {
+                result = sdf.parse(sa);
+            } catch (ParseException e) {
+            }
+        }
+
+        return result;
+    }
+
+    private double[] doConvertToDoubleArray(Map context, Object value) {
+        double[] result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            double[] da = new double[sa.length];
+
+            for (int i = 0; i < sa.length; i++) {
+                da[i] = ((Double) super.convertValue(context, sa[i], Double.class)).doubleValue();
+            }
+
+            result = da;
+        }
+
+        return result;
+    }
+
+    private Double[] doConvertToDoubleArray2(Map context, Object value) {
+        double[] primitives = doConvertToDoubleArray(context, value);
+        Double[] result = null;
+
+        if (primitives != null) {
+            result = new Double[primitives.length];
+
+            for (int i = 0; i < primitives.length; i++) {
+                double primitive = primitives[i];
+                result[i] = new Double(primitive);
+            }
+        }
+
+        return result;
+    }
+
+    private float[] doConvertToFloatArray(Map context, Object value) {
+        float[] result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            float[] da = new float[sa.length];
+
+            for (int i = 0; i < sa.length; i++) {
+                da[i] = ((Float) super.convertValue(context, sa[i], Float.class)).floatValue();
+            }
+
+            result = da;
+        }
+
+        return result;
+    }
+
+    private Float[] doConvertToFloatArray2(Map context, Object value) {
+        float[] primitives = doConvertToFloatArray(context, value);
+        Float[] result = null;
+
+        if (primitives != null) {
+            result = new Float[primitives.length];
+
+            for (int i = 0; i < primitives.length; i++) {
+                float primitive = primitives[i];
+                result[i] = new Float(primitive);
+            }
+        }
+
+        return result;
+    }
+
+    private int[] doConvertToIntArray(Map context, Object value) {
+        int[] result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            int[] ia = new int[sa.length];
+
+            for (int i = 0; i < sa.length; i++) {
+                ia[i] = ((Integer) super.convertValue(context, sa[i], Integer.class)).intValue();
+            }
+
+            result = ia;
+        }
+
+        return result;
+    }
+
+    private Integer[] doConvertToIntegerArray(Map context, Object value) {
+        int[] primitives = doConvertToIntArray(context, value);
+        Integer[] result = null;
+
+        if (primitives != null) {
+            result = new Integer[primitives.length];
+
+            for (int i = 0; i < primitives.length; i++) {
+                int primitive = primitives[i];
+                result[i] = new Integer(primitive);
+            }
+        }
+
+        return result;
+    }
+
+    private List doConvertToList(Map context, Object value) {
+        List result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            result = new ArrayList(sa.length);
+
+            for (int i = 0; i < sa.length; i++) {
+                String s = sa[i];
+                result.add(s);
+            }
+        }
+
+        return result;
+    }
+
+    private long[] doConvertToLongArray(Map context, Object value) {
+        long[] result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            long[] la = new long[sa.length];
+
+            for (int i = 0; i < sa.length; i++) {
+                la[i] = ((Long) super.convertValue(context, sa[i], Long.class)).longValue();
+            }
+
+            result = la;
+        }
+
+        return result;
+    }
+
+    private Long[] doConvertToLongArray2(Map context, Object value) {
+        long[] primitives = doConvertToLongArray(context, value);
+        Long[] result = null;
+
+        if (primitives != null) {
+            result = new Long[primitives.length];
+
+            for (int i = 0; i < primitives.length; i++) {
+                long primitive = primitives[i];
+                result[i] = new Long(primitive);
+            }
+        }
+
+        return result;
+    }
+
+    private Object doConvertToSet(Map context, Object value) {
+        Set result = null;
+
+        if (value instanceof String[]) {
+            String[] sa = (String[]) value;
+            result = new HashSet(sa.length);
+
+            for (int i = 0; i < sa.length; i++) {
+                String s = sa[i];
+                result.add(s);
+            }
+        }
+
+        return result;
+    }
+
+    private String doConvertToString(Map context, Object value) {
+        String result = null;
+
+        if (value instanceof int[]) {
+            int[] x = (int[]) value;
+            List intArray = new ArrayList(x.length);
+
+            for (int i = 0; i < x.length; i++) {
+                intArray.add(new Integer(x[i]));
+            }
+
+            result = TextUtils.join(", ", intArray);
+        } else if (value instanceof long[]) {
+            long[] x = (long[]) value;
+            List intArray = new ArrayList(x.length);
+
+            for (int i = 0; i < x.length; i++) {
+                intArray.add(new Long(x[i]));
+            }
+
+            result = TextUtils.join(", ", intArray);
+        } else if (value instanceof double[]) {
+            double[] x = (double[]) value;
+            List intArray = new ArrayList(x.length);
+
+            for (int i = 0; i < x.length; i++) {
+                intArray.add(new Double(x[i]));
+            }
+
+            result = TextUtils.join(", ", intArray);
+        } else if (value instanceof boolean[]) {
+            boolean[] x = (boolean[]) value;
+            List intArray = new ArrayList(x.length);
+
+            for (int i = 0; i < x.length; i++) {
+                intArray.add(new Boolean(x[i]));
+            }
+
+            result = TextUtils.join(", ", intArray);
+        } else if (value instanceof Date) {
+            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
+            result = sdf.format(value);
+        } else if (value instanceof String[]) {
+            result = TextUtils.join(", ", (String[]) value);
+        }
+
+        return result;
+    }
+}

File src/java/com/opensymphony/xwork/util/XWorkConverter.java

  */
 package com.opensymphony.xwork.util;
 
-import com.opensymphony.xwork.LocaleAware;
-import com.opensymphony.xwork.ValidationAware;
+import com.opensymphony.xwork.ActionContext;
+
 import ognl.DefaultTypeConverter;
 import ognl.Evaluation;
 import ognl.OgnlContext;
 import ognl.TypeConverter;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.io.InputStream;
+
 import java.lang.reflect.Member;
-import java.util.*;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
 
 
 /**
 
                     // ugly hack getting the property, but it works
                     property = eval.getNode().jjtGetChild(eval.getNode().jjtGetNumChildren() - 1).toString();
+
                     if (property.startsWith("\"") && property.endsWith("\"")) {
                         property = property.substring(1, property.length() - 1);
                     }
                             mapping.putAll(props);
 
                             for (Iterator iterator = mapping.entrySet().iterator();
-                                 iterator.hasNext();) {
+                                    iterator.hasNext();) {
                                 Map.Entry entry = (Map.Entry) iterator.next();
                                 entry.setValue(createTypeConverter((String) entry.getValue()));
                             }
 
         if (tc != null) {
             try {
-                Object returnVal = tc.convertValue(context, target, member, property, value, toClass);
-
-                if (returnVal == null) {
-                    handleConversionException(property, value, target);
-                }
-
-                return returnVal;
+                return tc.convertValue(context, target, member, property, value, toClass);
             } catch (Exception e) {
                 handleConversionException(property, value, target);
 
 
         if (defaultTypeConverter != null) {
             try {
-                Object returnVal = defaultTypeConverter.convertValue(context, target, member, property, value, toClass);
-
-                if (returnVal == null) {
-                    handleConversionException(property, value, target);
-                }
-
-                return returnVal;
+                return defaultTypeConverter.convertValue(context, target, member, property, value, toClass);
             } catch (Exception e) {
                 handleConversionException(property, value, target);
 
             }
         } else {
             try {
-                Object returnVal = super.convertValue(context, target, member, property, value, toClass);
-
-                if (returnVal == null) {
-                    handleConversionException(property, value, target);
-                }
-
-                return returnVal;
+                return super.convertValue(context, target, member, property, value, toClass);
             } catch (Exception e) {
                 handleConversionException(property, value, target);
 
     }
 
     protected void handleConversionException(String property, Object value, Object object) {
-        String defaultMessage = "Invalid field value for field " + property + ": " + value;
+        String defaultMessage = "Invalid field value for field \"" + property + "\".";
+        OgnlValueStack stack = ActionContext.getContext().getValueStack();
 
-        if ((object != null) && (object instanceof ValidationAware)) {
-            String message;
+        String getTextExpression = "getText('invalid.fieldvalue." + property + "','" + defaultMessage + "')";
+        String message = (String) stack.findValue(getTextExpression);
 
-            if (object instanceof LocaleAware) {
-                message = ((LocaleAware) object).getText("invalid.fieldvalue." + property, defaultMessage);
-            } else {
-                message = defaultMessage;
-            }
-
-            ((ValidationAware) object).addFieldError(property, message);
-        } else {
-            LOG.warn(defaultMessage);
+        if (message == null) {
+            message = defaultMessage;
         }
+
+        String addFieldErrorExpression = "addFieldError('" + property + "','" + message + "')";
+        stack.findValue(addFieldErrorExpression);
     }
 
     private TypeConverter createTypeConverter(String className) throws Exception, InstantiationException {
         props.load(is);
 
         for (Iterator iterator = props.entrySet().iterator();
-             iterator.hasNext();) {
+                iterator.hasNext();) {
             Map.Entry entry = (Map.Entry) iterator.next();
             String key = (String) entry.getKey();