click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r721899 - in /incubator/click/trunk/click: documentation/docs/ extras/src/net/sf/click/extras/control/ framework/src/net/sf/click/ framework/src/net/sf/click/control/ framework/test/net/sf/click/control/
Date Sun, 30 Nov 2008 21:22:01 GMT
Author: sabob
Date: Sun Nov 30 13:22:00 2008
New Revision: 721899

URL: http://svn.apache.org/viewvc?rev=721899&view=rev
Log:
Improved exception handling when control name is not defined. CLK-473

Modified:
    incubator/click/trunk/click/documentation/docs/roadmap-changes.html
    incubator/click/trunk/click/extras/src/net/sf/click/extras/control/AbstractContainerField.java
    incubator/click/trunk/click/framework/src/net/sf/click/Page.java
    incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractContainer.java
    incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractControl.java
    incubator/click/trunk/click/framework/src/net/sf/click/control/ActionButton.java
    incubator/click/trunk/click/framework/src/net/sf/click/control/ActionLink.java
    incubator/click/trunk/click/framework/src/net/sf/click/control/Field.java
    incubator/click/trunk/click/framework/src/net/sf/click/control/Table.java
    incubator/click/trunk/click/framework/test/net/sf/click/control/AbstractContainerTest.java

Modified: incubator/click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/documentation/docs/roadmap-changes.html?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ incubator/click/trunk/click/documentation/docs/roadmap-changes.html Sun Nov 30 13:22:00
2008
@@ -65,6 +65,10 @@
     </div>
     <ul style="padding: 0em; margin-left:0em;margin-bottom: 2em">
       <li class="change">
+        Improved exception handling when a Control name is not defined
+        [<a target='blank' href="http://www.avoka.com/jira/browse/CLK-473">473</a>].
+      </li>
+      <li class="change">
         Fixed WebappLoader to reload Velocity global macro's
         [<a target='blank' href="http://www.avoka.com/jira/browse/CLK-467">467</a>].
       </li>

Modified: incubator/click/trunk/click/extras/src/net/sf/click/extras/control/AbstractContainerField.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/net/sf/click/extras/control/AbstractContainerField.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/net/sf/click/extras/control/AbstractContainerField.java
(original)
+++ incubator/click/trunk/click/extras/src/net/sf/click/extras/control/AbstractContainerField.java
Sun Nov 30 13:22:00 2008
@@ -172,6 +172,22 @@
     }
 
     /**
+     * Set the parent of the Field.
+     *
+     * @see net.sf.click.Control#setParent(Object)
+     *
+     * @param parent the parent of the Control
+     * @throws IllegalArgumentException if the given parent instance is
+     * referencing <tt>this</tt> object: <tt>if (parent == this)</tt>
+     */
+    public void setParent(Object parent) {
+        if (parent == this) {
+            throw new IllegalArgumentException("Cannot set parent to itself");
+        }
+        this.parent = parent;
+    }
+
+    /**
      * Return the HTML head import statements for contained controls.
      *
      * @see net.sf.click.Control#getHtmlImports()

Modified: incubator/click/trunk/click/framework/src/net/sf/click/Page.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/Page.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/Page.java (original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/Page.java Sun Nov 30 13:22:00 2008
@@ -355,13 +355,15 @@
             throw new IllegalArgumentException("Null control parameter");
         }
         if (StringUtils.isBlank(control.getName())) {
-            throw new IllegalArgumentException("Control name not defined");
+            throw new IllegalArgumentException("Control name not defined: "
+                + control.getClass());
         }
 
+        // Note: set parent first as setParent might veto further processing
+        control.setParent(this);
+
         getControls().add(control);
         addModel(control.getName(), control);
-
-        control.setParent(this);
     }
 
     /**

Modified: incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractContainer.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractContainer.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractContainer.java
(original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractContainer.java
Sun Nov 30 13:22:00 2008
@@ -131,12 +131,6 @@
         }
         if (control instanceof Field) {
             Field field = (Field) control;
-            // Guard against fields without names, as they would throw
-            // exceptions later when binding their request values.
-            if (StringUtils.isBlank(field.getName())) {
-                String msg = "Field name not defined: " + field.getClass().getName();
-                throw new IllegalArgumentException(msg);
-            }
             // Check if container already contains the field. Labels can share
             // names though.
             if (getControlMap().containsKey(field.getName())
@@ -170,8 +164,9 @@
             logParentReset(control, currentParent);
         }
 
-        getControls().add(index, control);
+        // Note: set parent first since setParent might veto further processing
         control.setParent(this);
+        getControls().add(index, control);
 
         String controlName = control.getName();
         if (controlName != null) {

Modified: incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractControl.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractControl.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractControl.java (original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/control/AbstractControl.java Sun
Nov 30 13:22:00 2008
@@ -450,6 +450,8 @@
      * @see net.sf.click.Control#setParent(Object)
      *
      * @param parent the parent of the Control
+     * @throws IllegalArgumentException if the given parent instance is
+     * referencing <tt>this</tt> object: <tt>if (parent == this)</tt>
      */
     public void setParent(Object parent) {
         if (parent == this) {

Modified: incubator/click/trunk/click/framework/src/net/sf/click/control/ActionButton.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/control/ActionButton.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/control/ActionButton.java (original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/control/ActionButton.java Sun Nov
30 13:22:00 2008
@@ -222,6 +222,27 @@
     }
 
     /**
+     * Set the parent of the ActionButton.
+     *
+     * @see net.sf.click.Control#setParent(Object)
+     *
+     * @param parent the parent of the Control
+     * @throws IllegalStateException if {@link #name} is not defined
+     * @throws IllegalArgumentException if the given parent instance is
+     * referencing <tt>this</tt> object: <tt>if (parent == this)</tt>
+     */
+    public void setParent(Object parent) {
+        if (parent == this) {
+            throw new IllegalArgumentException("Cannot set parent to itself");
+        }
+        if (getName() == null) {
+            String msg = "ActionButton name not defined.";
+            throw new IllegalArgumentException(msg);
+        }
+        this.parent = parent;
+    }
+
+    /**
      * Return the ActionButton onclick attribute for the given value.
      * This method will encode the URL with the session ID if required using
      * <tt>HttpServletResponse.encodeURL()</tt>.

Modified: incubator/click/trunk/click/framework/src/net/sf/click/control/ActionLink.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/control/ActionLink.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/control/ActionLink.java (original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/control/ActionLink.java Sun Nov
30 13:22:00 2008
@@ -358,6 +358,27 @@
     }
 
     /**
+     * Set the parent of the ActionLink.
+     *
+     * @see net.sf.click.Control#setParent(Object)
+     *
+     * @param parent the parent of the Control
+     * @throws IllegalStateException if {@link #name} is not defined
+     * @throws IllegalArgumentException if the given parent instance is
+     * referencing <tt>this</tt> object: <tt>if (parent == this)</tt>
+     */
+    public void setParent(Object parent) {
+        if (parent == this) {
+            throw new IllegalArgumentException("Cannot set parent to itself");
+        }
+        if (getName() == null) {
+            String msg = "ActionLink name not defined.";
+            throw new IllegalArgumentException(msg);
+        }
+        this.parent = parent;
+    }
+
+    /**
      * Returns the ActionLink value if the action link was processed and has
      * a value, or null otherwise.
      *

Modified: incubator/click/trunk/click/framework/src/net/sf/click/control/Field.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/control/Field.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/control/Field.java (original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/control/Field.java Sun Nov 30 13:22:00
2008
@@ -241,6 +241,29 @@
     // ------------------------------------------------------ Public Attributes
 
     /**
+     * Set the parent of the Field.
+     *
+     * @see net.sf.click.Control#setParent(Object)
+     *
+     * @param parent the parent of the Control
+     * @throws IllegalStateException if {@link #name} is not defined
+     * @throws IllegalArgumentException if the given parent instance is
+     * referencing <tt>this</tt> object: <tt>if (parent == this)</tt>
+     */
+    public void setParent(Object parent) {
+        if (parent == this) {
+            throw new IllegalArgumentException("Cannot set parent to itself");
+        }
+        // Guard against fields without names, as fields would throw
+        // exceptions when binding to request value.
+        if (StringUtils.isBlank(getName())) {
+            String msg = "Field name not defined: " + getClass().getName();
+            throw new IllegalArgumentException(msg);
+        }
+        this.parent = parent;
+    }
+
+    /**
      * Return true if the Field is disabled. The Field will also be disabled
      * if the parent FieldSet or Form is disabled.
      * <p/>
@@ -586,7 +609,7 @@
         }
         return readonly;
     }
- 
+
     /**
      * Set the Field readonly flag.
      *

Modified: incubator/click/trunk/click/framework/src/net/sf/click/control/Table.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/net/sf/click/control/Table.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/net/sf/click/control/Table.java (original)
+++ incubator/click/trunk/click/framework/src/net/sf/click/control/Table.java Sun Nov 30 13:22:00
2008
@@ -444,6 +444,26 @@
      }
 
     /**
+     * Set the parent of the Table.
+     *
+     * @see net.sf.click.Control#setParent(Object)
+     *
+     * @param parent the parent of the Table
+     * @throws IllegalStateException if {@link #name} is not defined
+     * @throws IllegalArgumentException if the given parent instance is
+     * referencing <tt>this</tt> object: <tt>if (parent == this)</tt>
+     */
+    public void setParent(Object parent) {
+        if (parent == this) {
+            throw new IllegalArgumentException("Cannot set parent to itself");
+        }
+        if (getName() == null) {
+            throw new IllegalArgumentException("Table name is not defined");
+        }
+        this.parent = parent;
+    }
+
+    /**
      * Return the Table pagination banner position. Banner position values:
      * <tt>[ POSITION_TOP | POSITION_BOTTOM | POSITION_BOTH ]</tt>.
      * The default banner position is <tt>POSITION_BOTTOM</tt>.
@@ -629,10 +649,11 @@
         if (control == null) {
             throw new IllegalArgumentException("Null control parameter");
         }
-        getControls().add(control);
-
+        // Note: set parent first since setParent might veto further processing
         control.setParent(this);
 
+        getControls().add(control);
+
         return control;
     }
 

Modified: incubator/click/trunk/click/framework/test/net/sf/click/control/AbstractContainerTest.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/test/net/sf/click/control/AbstractContainerTest.java?rev=721899&r1=721898&r2=721899&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/test/net/sf/click/control/AbstractContainerTest.java
(original)
+++ incubator/click/trunk/click/framework/test/net/sf/click/control/AbstractContainerTest.java
Sun Nov 30 13:22:00 2008
@@ -1,6 +1,7 @@
 package net.sf.click.control;
 
 import junit.framework.TestCase;
+import net.sf.click.MockContext;
 
 /**
  * Test AbstractContainer behavior.
@@ -12,7 +13,7 @@
      * pre conditions.
      */
     public void testInsertPreCondistion() {
-
+        MockContext.initContext();
         AbstractContainer container = new AbstractContainer("form") {};
 
         // Check that adding null control fails
@@ -21,21 +22,21 @@
             fail("Control cannot be null");
         } catch (Exception expected) {
         }
-        
+
         // Check that inserting into invalid negative index is caught
         try {
             container.insert(new TextField("field"), -1);
             fail("insert index is out of bounds");
         } catch (Exception expected) {
         }
-        
+
         // Check that inserting into invalid positive index is caught
         try {
             container.insert(new TextField("field"), 1);
             fail("insert index is out of bounds");
         } catch (Exception expected) {
         }
-        
+
         // Check that inserting into valid index succeeds
         try {
             container.insert(new TextField("field"), 0);
@@ -43,7 +44,7 @@
             e.printStackTrace();
             fail("index 0 should be valid");
         }
-        
+
         // Create new container for testing
         container = new AbstractContainer("form") {};
 
@@ -54,7 +55,7 @@
             e.printStackTrace();
             fail("Field has name defined and is valid");
         }
-        
+
         // Check that adding TextField with duplicate name fails
         try {
             container.add(new TextField("field"));
@@ -71,6 +72,15 @@
             // Should fail since Field does not have name defined
         }
 
+        // Check that adding Table without name fails
+        try {
+            Table table = new Table();
+            container.add(table);
+            fail("Table must define a name");
+        } catch (Exception expected) {
+            // Should fail since Table does not have name defined
+        }
+
         // Check that adding Container without name succeeds
         try {
             container.add(new AbstractContainer() {});
@@ -86,7 +96,7 @@
             e.printStackTrace();
             fail("FieldSet has name defined and is valid");
         }
-        
+
         // Check that adding FieldSet with duplicate name fails
         try {
             container.add(new FieldSet("fieldSet"));
@@ -126,7 +136,7 @@
             e.printStackTrace();
             fail("Form should accept labels with duplicate names");
         }
-        
+
         // Check that adding container to itself fails
         try {
             container.add(container);



Mime
View raw message