click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r963082 - /click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java
Date Sun, 11 Jul 2010 14:42:22 GMT
Author: sabob
Date: Sun Jul 11 14:42:22 2010
New Revision: 963082

URL: http://svn.apache.org/viewvc?rev=963082&view=rev
Log:
added javadoc and small optimization

Modified:
    click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java

Modified: click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java?rev=963082&r1=963081&r2=963082&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java Sun Jul
11 14:42:22 2010
@@ -247,18 +247,33 @@ public abstract class AbstractControl im
     }
 
     /**
-     * Adds an AJAX Behavior.
+     * Add the given {@link org.apache.click.Behavior Behavior} to the control.
+     * <p/>
+     * <b>Stateful Page note:</b> care must be taken not to add duplicate behaviors.
+     * Duplicate behaviors can occur if a behavior is <tt>created</tt> and <tt>added</tt>
+     * to a Control in the {@link #onInit()} or {@link #onRender()} events.
+     * <p/>
+     * Instead add the behavior in the stateful Page constructor.
+     * If the Behavior must be added during the onInit event, declare the behavior
+     * as a Page variable to ensure the <tt>same instance</tt> is added to the
Control.
+     * Since control behaviors are contained in a Set, adding the same Behavior
+     * instance won't lead to duplicates.
      *
-     * @param behavior the AJAX behavior
+     * @param behavior the behavior to add
      */
     public void addBehavior(Behavior behavior) {
-        boolean added = getBehaviors().add(behavior);
-        if (added) {
+        if (behavior == null) {
+            throw new IllegalArgumentException("Behavior cannot be null");
+        }
+
+        // If the control has behaviors yet, register the control as an AJAX target
+        if (!hasBehaviors()) {
             // Register control here in case behavior was added *after* the onInit event.
             // This can occur if the behavior is added in a listener event or during
             // onRender.
             ControlRegistry.registerAjaxTarget(this);
         }
+        getBehaviors().add(behavior);
     }
 
     /**



Mime
View raw message