Commits

Anonymous committed 20d756e

Comments (0)

Files changed (4)

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

             tc = (TypeConverter) getConverter(clazz, property);
         }
 
+        if (tc == null && context != null) {
+            // ok, let's see if we can look it up by path as requested in XW-297
+            Object lastPropertyPath = context.get(OgnlContextState.CURRENT_PROPERTY_PATH);
+            Class clazz = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
+            if (lastPropertyPath != null && clazz != null) {
+                String path = lastPropertyPath + "." + property;
+                tc = (TypeConverter) getConverter(clazz, path);
+            }
+        }
+
         if (tc == null) {
             if (toClass.equals(String.class) && (value != null) && !(value.getClass().equals(String.class) || value.getClass().equals(String[].class)))
             {

src/test/com/opensymphony/xwork/util/Cat-conversion.properties

 Collection_kittens = com.opensymphony.xwork.util.Cat
+foo.number = com.opensymphony.xwork.util.FooNumberConverter

src/test/com/opensymphony/xwork/util/FooNumberConverter.java

+package com.opensymphony.xwork.util;
+
+import ognl.DefaultTypeConverter;
+
+import java.util.Map;
+
+public class FooNumberConverter extends DefaultTypeConverter {
+    public Object convertValue(Map map, Object object, Class aClass) {
+        String s = (String) object;
+
+        int length = s.length();
+        StringBuffer r = new StringBuffer();
+        for (int i = length; i > 0; i--) {
+            r.append(s.charAt(i - 1));
+        }
+
+        return super.convertValue(map, r.toString(), aClass);
+    }
+}

src/test/com/opensymphony/xwork/util/XWorkConverterTest.java

         assertNotNull(bar);
     }
 
+    public void testNestedConverters() {
+        OgnlValueStack stack = new OgnlValueStack();
+        Cat cat = new Cat();
+        cat.setFoo(new Foo());
+        stack.push(cat);
+        stack.setValue("foo.number", "123");
+        assertEquals(321, cat.getFoo().getNumber());
+    }
+
     public static class Foo1 {
         public Bar1 getBar() {
             return new Bar1Impl();