You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ni...@apache.org on 2006/11/29 16:17:52 UTC

svn commit: r480593 - in /struts/struts1/trunk/core/src: main/java/org/apache/struts/config/ActionConfig.java test/java/org/apache/struts/config/TestActionConfig.java

Author: niallp
Date: Wed Nov 29 07:17:52 2006
New Revision: 480593

URL: http://svn.apache.org/viewvc?view=rev&rev=480593
Log:
STR-2955 - extending action is still overriden when validate is specifically set to true or cancellable is set to false - reported by Mark Shifman

Modified:
    struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java
    struts/struts1/trunk/core/src/test/java/org/apache/struts/config/TestActionConfig.java

Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java?view=diff&rev=480593&r1=480592&r2=480593
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java Wed Nov 29 07:17:52 2006
@@ -35,8 +35,7 @@
  * <code>&lt;action&gt;</code> element from a Struts module configuration
  * file.</p>
  *
- * @version $Rev$ $Date: 2005-08-06 04:12:10 -0400 (Sat, 06 Aug 2005)
- *          $
+ * @version $Rev$ $Date$
  * @since Struts 1.1
  */
 public class ActionConfig extends BaseConfig {
@@ -85,6 +84,11 @@
     protected String inherit = null;
 
     /**
+     * Indicates whether the "cancellable " property has been set or not.
+     */
+    private boolean cancellableSet = false;
+
+    /**
      * <p>Can this Action be cancelled? [false]</p> <p> By default, when an
      * Action is cancelled, validation is bypassed and the Action should not
      * execute the business operation. If a request tries to cancel an Action
@@ -195,6 +199,11 @@
     protected boolean unknown = false;
 
     /**
+     * Indicates whether the "validate" property has been set or not.
+     */
+    private boolean validateSet = false;
+
+    /**
      * <p> Should the <code>validate()</code> method of the form bean
      * associated with this action be called?
      */
@@ -323,6 +332,7 @@
         }
 
         this.cancellable = cancellable;
+        this.cancellableSet = true;
     }
 
     /**
@@ -677,6 +687,7 @@
         }
 
         this.validate = validate;
+        this.validateSet = true;
     }
 
     /**
@@ -1028,7 +1039,7 @@
             setAttribute(config.getAttribute());
         }
 
-        if (!getCancellable()) {
+        if (!cancellableSet) {
             setCancellable(config.getCancellable());
         }
 
@@ -1092,7 +1103,7 @@
             setUnknown(config.getUnknown());
         }
 
-        if (getValidate()) {
+        if (!validateSet) {
             setValidate(config.getValidate());
         }
 

Modified: struts/struts1/trunk/core/src/test/java/org/apache/struts/config/TestActionConfig.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/test/java/org/apache/struts/config/TestActionConfig.java?view=diff&rev=480593&r1=480592&r2=480593
==============================================================================
--- struts/struts1/trunk/core/src/test/java/org/apache/struts/config/TestActionConfig.java (original)
+++ struts/struts1/trunk/core/src/test/java/org/apache/struts/config/TestActionConfig.java Wed Nov 29 07:17:52 2006
@@ -310,6 +310,55 @@
     }
 
     /**
+     * Make sure that correct exception is thrown if a base action can't be
+     * found.
+     */
+    public void testInheritBoolean()
+        throws Exception {
+
+        ActionConfig parentConfig = new ActionConfig();
+        parentConfig.setPath("/parent");
+        ActionConfig childConfig  = null;
+
+        // Test if boolean is NOT set it IS inherited
+        parentConfig.setValidate(true);
+        parentConfig.setCancellable(true);
+        childConfig = new ActionConfig();
+        childConfig.inheritFrom(parentConfig);
+        assertEquals("default validate inherit true", true, childConfig.getValidate());
+        assertEquals("default cancellable inherit true", true, childConfig.getValidate());
+
+        // Test if boolean is NOT set it IS inherited
+        parentConfig.setValidate(false);
+        parentConfig.setCancellable(false);
+        childConfig = new ActionConfig();
+        childConfig.inheritFrom(parentConfig);
+        assertEquals("default validate inherit false", false, childConfig.getValidate());
+        assertEquals("default cancellable inherit false", false, childConfig.getValidate());
+
+        // Test if boolean IS set it is NOT inherited
+        parentConfig.setValidate(true);
+        parentConfig.setCancellable(true);
+        childConfig = new ActionConfig();
+        childConfig.setValidate(false);
+        childConfig.setCancellable(false);
+        childConfig.inheritFrom(parentConfig);
+        assertEquals("set validate (not inherit true)", false, childConfig.getValidate());
+        assertEquals("set cancellable (not inherit false)", false, childConfig.getValidate());
+
+        // Test if boolean IS set it is NOT inherited
+        parentConfig.setValidate(false);
+        parentConfig.setCancellable(false);
+        childConfig = new ActionConfig();
+        childConfig.setValidate(true);
+        childConfig.setCancellable(true);
+        childConfig.inheritFrom(parentConfig);
+        assertEquals("set validate (not inherit false)", true, childConfig.getValidate());
+        assertEquals("set cancellable (not inherit false)", true, childConfig.getValidate());
+
+    }
+
+    /**
      * Used to detect that ActionConfig is making the right calls.
      */
     public static class CustomActionConfig extends ActionConfig {