Commits

Anonymous committed 55fa6e3

Completed: Chain Result throws Exception when you use a actionName with a method (http://jira.opensymphony.com/browse/XW-332)
Added method parameter

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

  • Participants
  • Parent commits 15e4f13

Comments (0)

Files changed (1)

File src/java/com/opensymphony/xwork/ActionChainResult.java

  * <li><b>namespace</b> - used to determine which namespace the Action is in that we're chaining. If namespace is null,
  * this defaults to the current namespace</li>
  *
+ * <li><b>method</b> - used to specify another method on target action to be invoked. 
+ * If null, this defaults to execute method</li>
+ * 
  * </ul>
  *
  * <!-- END SNIPPET: params -->
  *     &lt;/action&gt;
  * &lt;/package&gt;
  * <!-- END SNIPPET: example --></pre>
+ * 
+ * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  */
 public class ActionChainResult implements Result {
 
     private String actionName;
 
     private String namespace;
+    
+    private String methodName;
 
 
     public void setActionName(String actionName) {
         this.namespace = namespace;
     }
 
+    public void setMethod(String method) {
+        this.methodName = method;
+    }
+    
     public ActionProxy getProxy() {
         return proxy;
     }
         OgnlValueStack stack = ActionContext.getContext().getValueStack();
         String finalNamespace = TextParseUtil.translateVariables(namespace, stack);
         String finalActionName = TextParseUtil.translateVariables(actionName, stack);
+        String finalMethodName = this.methodName != null 
+                ? TextParseUtil.translateVariables(this.methodName, stack)
+                : null;
 
-        if (isInChainHistory(finalNamespace, finalActionName)) {
+        if (isInChainHistory(finalNamespace, finalActionName, finalMethodName)) {
             throw new XworkException("infinite recursion detected");
         }
 
-        addToHistory(finalNamespace, finalActionName);
+        addToHistory(finalNamespace, finalActionName, finalMethodName);
 
         HashMap extraContext = new HashMap();
         extraContext.put(ActionContext.VALUE_STACK, ActionContext.getContext().getValueStack());
         }
 
         proxy = ActionProxyFactory.getFactory().createActionProxy(finalNamespace, finalActionName, extraContext);
+        if (null != finalMethodName) {
+            proxy.setMethod(finalMethodName);
+        }
         proxy.execute();
     }
 
         return ((actionName != null) ? actionName.hashCode() : 0);
     }
 
-    private boolean isInChainHistory(String namespace, String actionName) {
+    private boolean isInChainHistory(String namespace, String actionName, String methodName) {
         Set chainHistory = (Set) ActionContext.getContext().get(CHAIN_HISTORY);
 
         if (chainHistory == null) {
             return false;
         } else {
-            return chainHistory.contains(makeKey(namespace, actionName));
+            return chainHistory.contains(makeKey(namespace, actionName, methodName));
         }
     }
 
-    private void addToHistory(String namespace, String actionName) {
+    private void addToHistory(String namespace, String actionName, String methodName) {
         Set chainHistory = (Set) ActionContext.getContext().get(CHAIN_HISTORY);
 
         if (chainHistory == null) {
 
         ActionContext.getContext().put(CHAIN_HISTORY, chainHistory);
 
-        chainHistory.add(makeKey(namespace, actionName));
+        chainHistory.add(makeKey(namespace, actionName, methodName));
     }
 
-    private String makeKey(String namespace, String actionName) {
-        return namespace + "/" + actionName;
+    private String makeKey(String namespace, String actionName, String methodName) {
+        if (null == methodName) {
+            return namespace + "/" + actionName;
+        }
+        
+        return namespace + "/" + actionName + "!" + methodName;
     }
 }