Commits

Anonymous committed 5a4d657

more javascript-based client side validation:
* commands can be specified at runtime and honor doXxx and xxx (foo!default) (WW-502)
* the client side validation uses the action you are submitting to, not the current one

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

  • Participants
  • Parent commits d9a4cae

Comments (0)

Files changed (7)

src/java/com/opensymphony/xwork/ActionSupport.java

         return SUCCESS;
     }
 
+    public String doDefault() {
+        return SUCCESS;
+    }
+
     public boolean hasActionErrors() {
         return validationAware.hasActionErrors();
     }

src/java/com/opensymphony/xwork/DefaultActionProxy.java

         this.namespace = namespace;
         this.executeResult = executeResult;
         this.extraContext = extraContext;
+
         config = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, actionName);
 
         if (config == null) {

src/java/com/opensymphony/xwork/DefaultActionProxyFactory.java

  */
 package com.opensymphony.xwork;
 
+import com.opensymphony.xwork.config.ConfigurationManager;
+import com.opensymphony.xwork.config.entities.ActionConfig;
+
 import java.util.Map;
 
 
     * Use this method to build an DefaultActionProxy instance.
     */
     public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext) throws Exception {
+        setupConfigIfActionIsCommand(namespace, actionName);
         return new DefaultActionProxy(namespace, actionName, extraContext, true);
     }
 
     * Use this method to build an DefaultActionProxy instance.
     */
     public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext, boolean executeResult) throws Exception {
+        setupConfigIfActionIsCommand(namespace, actionName);
         return new DefaultActionProxy(namespace, actionName, extraContext, executeResult);
     }
+
+    private void setupConfigIfActionIsCommand(String namespace, String actionName) {
+        if (ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, actionName) != null) {
+            return;
+        }
+
+        int bang = actionName.indexOf('!');
+        if (bang != -1) {
+            String realAction = actionName.substring(0, bang);
+            String command = actionName.substring(bang + 1);
+
+            ActionConfig actionConfig
+                    = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, realAction);
+            ActionConfig newConfig = new ActionConfig(command, actionConfig.getClazz(), actionConfig.getParams(),
+                    actionConfig.getResults(), actionConfig.getInterceptors(), actionConfig.getExternalRefs(),
+                    actionConfig.getPackageName());
+
+            ConfigurationManager.getConfiguration().getPackageConfig(newConfig.getPackageName()).addActionConfig(actionName, newConfig);
+            ConfigurationManager.getConfiguration().rebuildRuntimeConfiguration();
+        }
+    }
 }

src/java/com/opensymphony/xwork/config/Configuration.java

      */
     void reload() throws ConfigurationException;
 
+    public void rebuildRuntimeConfiguration();
+
     void removePackageConfig(String name);
 }

src/java/com/opensymphony/xwork/config/entities/ActionConfig.java

         }
 
         if (methodName != null) {
-            method = clazz.getMethod(methodName, new Class[0]);
+            try {
+                method = clazz.getMethod(methodName, new Class[0]);
+            } catch (NoSuchMethodException e) {
+                try {
+                    method = clazz.getMethod("do" + String.valueOf(methodName.charAt(0)).toUpperCase() + methodName.substring(1), new Class[0]);
+                } catch (NoSuchMethodException e1) {
+                    throw e;
+                }
+            }
         } else // return default execute() method if method name is not specified
          {
             method = clazz.getMethod("execute", new Class[0]);

src/java/com/opensymphony/xwork/config/impl/DefaultConfiguration.java

             provider.init(this);
         }
 
-        runtimeConfiguration = buildRuntimeConfiguration();
+        rebuildRuntimeConfiguration();
     }
 
     public void removePackageConfig(String name) {
         }
     }
 
+    public void rebuildRuntimeConfiguration() {
+        runtimeConfiguration = buildRuntimeConfiguration();
+    }
+
     /**
     * This methodName builds the internal runtime configuration used by Xwork for finding and configuring Actions from the
     * programmatic configuration data structures. All of the old runtime configuration will be discarded and rebuilt.

src/test/com/opensymphony/xwork/config/impl/MockConfiguration.java

         throw new UnsupportedOperationException();
     }
 
+    public void rebuildRuntimeConfiguration() {
+        throw new UnsupportedOperationException();
+    }
+
     public void removePackageConfig(String name) {
     }
 }