mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
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.
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1065743 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -83,7 +83,7 @@ public class JSONInterceptor extends AbstractInterceptor {
|
||||
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 AbstractInterceptor {
|
||||
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 AbstractInterceptor {
|
||||
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 AbstractInterceptor {
|
||||
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);
|
||||
|
||||
@@ -322,6 +322,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
|
||||
TestAction action = new TestAction();
|
||||
|
||||
this.invocation.setAction(action);
|
||||
this.invocation.getStack().push(action);
|
||||
|
||||
interceptor.intercept(this.invocation);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user