Commits

Anonymous committed 8fc2d49

XW-88: Making Map's entries available when the map is pushed onto the ValueStack

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

  • Participants
  • Parent commits f9af682

Comments (0)

Files changed (2)

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

                 Object o = iterator.next();
 
                 try {
-                    if (OgnlRuntime.hasGetProperty(ognlContext, o, name)) {
+                    if ((OgnlRuntime.hasGetProperty(ognlContext, o, name)) || ((o instanceof Map) && ((Map)o).containsKey(name))) {
                         Object value = OgnlRuntime.getProperty(ognlContext, o, name);
 
                         //Ognl.getValue(OgnlUtil.compile((String) name), context, o);

File src/test/com/opensymphony/xwork/util/OgnlValueStackTest.java

         assertEquals("bar", foo.getBar().getTitle());
         assertEquals(123, foo.getBar().getSomethingElse());
     }
+
+    public void testMapEntriesAvailableByKey() {
+        Foo foo = new Foo();
+        String title = "a title";
+        foo.setTitle(title);
+        OgnlValueStack vs = new OgnlValueStack();
+        vs.push(foo);
+
+        Map map = new HashMap();
+        String a_key = "a";
+        String a_value = "A";
+        map.put(a_key,a_value);
+        String b_key = "b";
+        String b_value = "B";
+        map.put(b_key,b_value);
+
+        vs.push(map);
+
+        assertEquals(title, vs.findValue("title"));
+        assertEquals(a_value, vs.findValue(a_key));
+        assertEquals(b_value, vs.findValue(b_key));
+    }
 }