@Override public void onComponentTag(Component aComponent, ComponentTag aTag) { for (IBehavior behavior : behaviors) { behavior.onComponentTag(aComponent, aTag); } }
@Override public void afterRender(Component aComponent) { for (IBehavior behavior : behaviors) { behavior.afterRender(aComponent); } }
@Override public void beforeRender(Component aComponent) { for (IBehavior behavior : behaviors) { behavior.beforeRender(aComponent); } }
behavior.onComponentTag(this, tag); if (behavior.isEnabled(this)) behavior.onComponentTag(this, tag); behavior.detach(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); } } }
/** * 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; }
@Override public boolean isEnabled(Component aComponent) { for (IBehavior behavior : behaviors) { if (!behavior.isEnabled(aComponent)) { return false; } } return true; }
@Override public void exception(Component aComponent, RuntimeException aException) { for (IBehavior behavior : behaviors) { behavior.exception(aComponent, aException); } }
@Override public void bind(Component aComponent) { for (IBehavior behavior : behaviors) { behavior.bind(aComponent); } }
@Override public void detach(Component aComponent) { for (IBehavior behavior : behaviors) { behavior.detach(aComponent); } }
/** * Returns if the component is stateless or not. It checks the stateless hint if that is false * it returns directly false. If that is still true it checks all its behaviors if they can be * stateless. * * @return whether the component is stateless. */ public final boolean isStateless() { if (!getStatelessHint()) { return false; } final Iterator behaviors = getBehaviors().iterator(); while (behaviors.hasNext()) { IBehavior behavior = (IBehavior)behaviors.next(); if (!behavior.getStatelessHint(this)) { return false; } } return true; }
/** * 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() { 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); } } } }
if (!behavior.isTemporary()) behavior.bind(this);
/** * Components are allowed to reject behavior modifiers. * * @param behavior * @return False, if the component should not apply this behavior */ protected boolean isBehaviorAccepted(final IBehavior behavior) { // Ignore AttributeModifiers when FLAG_IGNORE_ATTRIBUTE_MODIFIER is set if ((behavior instanceof AttributeModifier) && (getFlag(FLAG_IGNORE_ATTRIBUTE_MODIFIER) != false)) { return false; } return behavior.isEnabled(this); }
behavior.exception(this, ex);
@Override public void bind(Component aComponent) { super.bind(aComponent); for (IBehavior behavior: createLocalizedBehaviors(aComponent) ) { behavior.bind(aComponent); add(behavior); } }
/** * Returns if the component is stateless or not. It checks the stateless hint if that is false * it returns directly false. If that is still true it checks all its behaviors if they can be * stateless. * * @return whether the component is stateless. */ public final boolean isStateless() { if (!getStatelessHint()) { return false; } for (IBehavior behavior : getBehaviors()) { if (!behavior.getStatelessHint(this)) { return false; } } return true; }
/** * 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; }
behavior.onComponentTag(this, tag); behavior.onComponentTag(this, tag);