org.apache.wicket.behavior
Class Behavior

java.lang.Object
  extended by org.apache.wicket.behavior.Behavior
All Implemented Interfaces:
java.io.Serializable, IClusterable, IComponentAwareEventSink, IComponentAwareHeaderContributor
Direct Known Subclasses:
AbstractAjaxBehavior, AbstractBehavior, AbstractFormValidator, AbstractTransformerBehavior, AbstractValidator, AjaxIndicatorAppender, AttributeModifier, BorderBehavior, CompoundValidator, ContextPathGenerator, DatePicker, FormValidatorAdapter, MaximumValidator, MinimumValidator, OrderByLink.CssModifier, RangeValidator, SimpleAttributeModifier, ValidatorAdapter, VelocityContributor, WicketMessageTagHandler.AttributeLocalizer

public abstract class Behavior
extends java.lang.Object
implements IClusterable, IComponentAwareEventSink, IComponentAwareHeaderContributor

Behaviors are kind of plug-ins for Components. They allow functionality to be added to a component and get essential events forwarded by the component. They can be bound to a concrete component (using the bind method which is called when the behavior is attached), but they don't need to. They can modify the components markup by changing the rendered ComponentTag. Behaviors can have their own models as well, and they are notified when these are to be detached by the component.

You also cannot modify a components model with a behavor.

Author:
Ralf Ebert, Eelco Hillenius, Igor Vaynberg (ivaynberg)
See Also:
IBehaviorListener, IHeaderContributor, AbstractAjaxBehavior, AttributeModifier, Serialized Form

Constructor Summary
Behavior()
           
 
Method Summary
 void afterRender(Component component)
          Called when a component that has this behavior coupled was rendered.
 void beforeRender(Component component)
          Called when a component is about to render.
 void bind(Component component)
          Bind this handler to the given component.
 boolean canCallListenerInterface(Component component)
          Checks if a listener can be invoked on this behavior
 void detach(Component component)
          Allows the behavior to detach any state it has attached during request processing.
 boolean getStatelessHint(Component component)
          This method returns false if the behavior generates a callback url (for example ajax behaviors)
 boolean isEnabled(Component component)
          Called when a components is rendering and wants to render this behavior.
 boolean isTemporary(Component component)
          Specifies whether or not this behavior is temporary.
 void onComponentTag(Component component, ComponentTag tag)
          Called any time a component that has this behavior registered is rendering the component tag.
 void onConfigure(Component component)
          Called immediately after the onConfigure method in a component.
 void onEvent(Component component, IEvent<?> event)
          Called to notify the behavior about any events sent to the component
 void onException(Component component, java.lang.RuntimeException exception)
          In case an unexpected exception happened anywhere between onComponentTag() and rendered(), onException() will be called for any behavior.
 void renderHead(Component component, IHeaderResponse response)
          Render to the web response whatever the component wants to contribute to the head section.
 void unbind(Component component)
          Notifies the behavior it is removed from the specified component
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Behavior

public Behavior()
Method Detail

beforeRender

public void beforeRender(Component component)
Called when a component is about to render.

Parameters:
component - the component that has this behavior coupled

afterRender

public void afterRender(Component component)
Called when a component that has this behavior coupled was rendered.

Parameters:
component - the component that has this behavior coupled

bind

public void bind(Component component)
Bind this handler to the given component. This method is called by the host component immediately after this behavior is added to it. This method is useful if you need to do initialization based on the component it is attached and you can't wait to do it at render time. Keep in mind that if you decide to keep a reference to the host component, it is not thread safe anymore, and should thus only be used in situations where you do not reuse the behavior for multiple components.

Parameters:
component - the component to bind to

unbind

public void unbind(Component component)
Notifies the behavior it is removed from the specified component

Parameters:
component - the component this behavior is unbound from

detach

public void detach(Component component)
Allows the behavior to detach any state it has attached during request processing.

Parameters:
component - the component that initiates the detachment of this behavior

onException

public void onException(Component component,
                        java.lang.RuntimeException exception)
In case an unexpected exception happened anywhere between onComponentTag() and rendered(), onException() will be called for any behavior. Typically, if you clean up resources in afterRender(Component), you should do the same in the implementation of this method.

Parameters:
component - the component that has a reference to this behavior and during which processing the exception occurred
exception - the unexpected exception

getStatelessHint

public boolean getStatelessHint(Component component)
This method returns false if the behavior generates a callback url (for example ajax behaviors)

Parameters:
component - the component that has this behavior coupled.
Returns:
boolean true or false.

isEnabled

public boolean isEnabled(Component component)
Called when a components is rendering and wants to render this behavior. If false is returned this behavior will be ignored.

Parameters:
component - the component that has this behavior coupled
Returns:
true if this behavior must be executed/rendered

onComponentTag

public void onComponentTag(Component component,
                           ComponentTag tag)
Called any time a component that has this behavior registered is rendering the component tag.

Parameters:
component - the component that renders this tag currently
tag - the tag that is rendered

isTemporary

public boolean isTemporary(Component component)
Specifies whether or not this behavior is temporary. Temporary behaviors are removed at the end of request and never reattached. Such behaviors are useful for modifying component rendering only when it renders next. Usecases include javascript effects, initial clientside dom setup, etc.

Parameters:
component -
Returns:
true if this behavior is temporary

canCallListenerInterface

public boolean canCallListenerInterface(Component component)
Checks if a listener can be invoked on this behavior

Parameters:
component -
Returns:
true if a listener interface can be invoked on this behavior

renderHead

public void renderHead(Component component,
                       IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.

Specified by:
renderHead in interface IComponentAwareHeaderContributor
Parameters:
component -
response - Response object

onConfigure

public void onConfigure(Component component)
Called immediately after the onConfigure method in a component. Since this is before the rendering cycle has begun, the behavior can modify the configuration of the component (i.e. setVisible(false))

Parameters:
component - the component being configured

onEvent

public void onEvent(Component component,
                    IEvent<?> event)
Called to notify the behavior about any events sent to the component

Specified by:
onEvent in interface IComponentAwareEventSink
Parameters:
component - component that owns this sink. For example, if the implementation of this interface is a Behavior then component parameter will contain the component to which the behavior is attached.
See Also:
IComponentAwareEventSink.onEvent(org.apache.wicket.Component, org.apache.wicket.event.IEvent)


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.