Author: jafl Date: Mon Jan 31 20:16:38 2011 New Revision: 1065743 URL: http://svn.apache.org/viewvc?rev=1065743&view=rev Log: WW-3498 Inject values into top of stack (model or action) instead of always using action. This does not break backward compatibility because nobody could use a model before this patch.
Modified: struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java Modified: struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java?rev=1065743&r1=1065742&r2=1065743&view=diff ============================================================================== --- struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java (original) +++ struts/struts2/trunk/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java Mon Jan 31 20:16:38 2011 @@ -83,7 +83,7 @@ public class JSONInterceptor extends Abs contentType = contentType.substring(0, iSemicolonIdx); } - Object rootObject; + Object rootObject = null; if (this.root != null) { ValueStack stack = invocation.getStack(); rootObject = stack.findValue(this.root); @@ -91,8 +91,6 @@ public class JSONInterceptor extends Abs if (rootObject == null) { throw new RuntimeException("Invalid root expression: '" + this.root + "'."); } - } else { - rootObject = invocation.getAction(); } if ((contentType != null) && contentType.equalsIgnoreCase("application/json")) { @@ -106,6 +104,9 @@ public class JSONInterceptor extends Abs if (dataCleaner != null) dataCleaner.clean("", json); + if (rootObject == null) // model overrides action + rootObject = invocation.getStack().peek(); + // populate fields populator.populateObject(rootObject, json); } else { @@ -121,6 +122,9 @@ public class JSONInterceptor extends Abs if (obj instanceof Map) { Map smd = (Map) obj; + if (rootObject == null) // model makes no sense when using RPC + rootObject = invocation.getAction(); + // invoke method try { result = this.invoke(rootObject, smd); Modified: struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java?rev=1065743&r1=1065742&r2=1065743&view=diff ============================================================================== --- struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java (original) +++ struts/struts2/trunk/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java Mon Jan 31 20:16:38 2011 @@ -322,6 +322,7 @@ public class JSONInterceptorTest extends TestAction action = new TestAction(); this.invocation.setAction(action); + this.invocation.getStack().push(action); interceptor.intercept(this.invocation);