/** * THIS IS WICKET INTERNAL ONLY. DO NOT USE IT. * * Traverses all behaviors and calls detachModel() on them. This is needed to cleanup behavior * after render. This method is necessary for {@link AjaxRequestTarget} to be able to cleanup * component's behaviors after header contribution has been done (which is separated from * component render). */ public final void detachBehaviors() { List behaviors = getBehaviorsImpl(); if (behaviors != null) { for (Iterator i = behaviors.iterator(); i.hasNext();) { IBehavior behavior = (IBehavior)i.next(); // Always detach models, 'accepted' or not. Otherwise, if they // are accepted during render, but not here - something can go // undetached, and calling isEnabled can also lead to nasty side // effects. See for instance Timo's comment on // http://issues.apache.org/jira/browse/WICKET-673 behavior.detach(this); if (behavior.isTemporary()) { removeBehavior(behavior); } } } }
/** * Removes behavior from component * * @param behavior * behavior to remove * * @return this (to allow method call chaining) */ public Component remove(final IBehavior behavior) { if (behavior == null) { throw new IllegalArgumentException("Argument `behavior` cannot be null"); } if (removeBehavior(behavior)) { if (!behavior.isTemporary()) { addStateChange(new RemovedBehaviorChange(behavior)); } } else { throw new IllegalStateException( "Tried to remove a behavior that was not added to the component. Behavior: " + behavior.toString()); } return this; }
/** * Removes behavior from component * * @param behavior * behavior to remove * * @return this (to allow method call chaining) */ public Component remove(final IBehavior behavior) { if (behavior == null) { throw new IllegalArgumentException("Argument `behavior` cannot be null"); } if (removeBehavior(behavior)) { if (!behavior.isTemporary()) { addStateChange(new RemovedBehaviorChange(behavior)); } } else { throw new IllegalStateException( "Tried to remove a behavior that was not added to the component. Behavior: " + behavior.toString()); } return this; }
/** * THIS IS WICKET INTERNAL ONLY. DO NOT USE IT. * * Traverses all behaviors and calls detachModel() on them. This is needed to cleanup behavior * after render. This method is necessary for {@link AjaxRequestTarget} to be able to cleanup * component's behaviors after header contribution has been done (which is separated from * component render). */ public final void detachBehaviors() { for (IBehavior behavior : getBehaviors()) { // Always detach models, 'accepted' or not. Otherwise, if they // are accepted during render, but not here - something can go // undetached, and calling isEnabled can also lead to nasty side // effects. See for instance Timo's comment on // http://issues.apache.org/jira/browse/WICKET-673 behavior.detach(this); if (behavior.isTemporary()) { removeBehavior(behavior); } } }
if (!behavior.isTemporary())
/** * Adds an behavior modifier to the component. * * <p> * Note: this method is override to enable users to do things like discussed in <a * href="http://www.nabble.com/Why-add%28IBehavior%29-is-final--tf2598263.html#a7248198">this * thread</a>. * </p> * * @param behavior * The behavior modifier to be added * @return this (to allow method call chaining) */ public Component add(final IBehavior behavior) { if (behavior == null) { throw new IllegalArgumentException("Argument may not be null"); } addBehavior(behavior); if (!behavior.isTemporary()) { addStateChange(new AddedBehaviorChange(behavior)); } // Give handler the opportunity to bind this component behavior.bind(this); return this; }