Commits

Anonymous committed 2f4a4fa

Fix for XW-271: Child property determination for localization

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2/src@1053e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

java/com/opensymphony/xwork/util/LocalizedTextUtil.java

 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.ModelDriven;
+
+import ognl.OgnlException;
+import ognl.OgnlRuntime;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.beans.IntrospectionException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
             }
 
             if (prop != null) {
-                Object obj = valueStack.findValue(prop);
-
-                if (obj != null) {
-                    Class clazz = obj.getClass();
-
-                    if (clazz != null) {
-                        valueStack.push(obj);
-                        msg = findText(clazz, newKey, locale, null, args);
-                        valueStack.pop();
-
-                        if (msg != null) {
-                            return msg;
+                try {
+                    Object realTarget = OgnlUtil.getRealTarget(prop, valueStack.getContext(), valueStack.getRoot());
+                    
+                    if (realTarget != null) {
+                        Class clazz = OgnlRuntime.getPropertyDescriptor(realTarget.getClass(), prop).getPropertyType();
+                        
+                        if (clazz != null) {
+                            msg = findText(clazz, newKey, locale, null, args);
+                            if (msg != null) {
+                                return msg;
+                            }
                         }
                     }
                 }
+                catch(OgnlException ognlex) {
+                    ; // ignore
+                }
+                catch(IntrospectionException ie) {
+                    ; // ignore
+                }
             }
         }
 

test/com/opensymphony/xwork/util/LocalizedTextUtilTest.java

         assertEquals("Title:", message);
     }
 
+    public void testActionGetTextWithNull() throws Exception {
+        ModelDrivenAction2 action = new ModelDrivenAction2();
+        TestBean2 bean = (TestBean2) action.getModel();
+
+        Mock mockActionInvocation = new Mock(ActionInvocation.class);
+        mockActionInvocation.expectAndReturn("getAction", action);
+        ActionContext.getContext().setActionInvocation((ActionInvocation) mockActionInvocation.proxy());
+        ActionContext.getContext().getValueStack().push(action);
+        ActionContext.getContext().getValueStack().push(action.getModel());
+
+        String message = action.getText("barObj.title");
+        assertEquals("Title:", message);
+    }
+    
     public void testNullKeys() {
         LocalizedTextUtil.findText(this.getClass(), null, Locale.getDefault());
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.