org.apache.wicket.ajax
Class AjaxEventBehavior

java.lang.Object
  extended by org.apache.wicket.behavior.AbstractBehavior
      extended by org.apache.wicket.behavior.AbstractAjaxBehavior
          extended by org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
              extended by org.apache.wicket.ajax.AjaxEventBehavior
All Implemented Interfaces:
java.io.Serializable, IBehavior, IBehaviorListener, IClusterable, IRequestListener, IHeaderContributor
Direct Known Subclasses:
AjaxEditableLabel.LabelAjaxBehavior, AjaxFormComponentUpdatingBehavior, AjaxFormSubmitBehavior, AjaxPagingNavigationBehavior

public abstract class AjaxEventBehavior
extends AbstractDefaultAjaxBehavior

An ajax behavior that is attached to a certain client-side (usually javascript) event, such as onClick, onChange, onKeyDown, etc.

Example:

         WebMarkupContainer div=new WebMarkupContainer(...);
         div.setOutputMarkupId(true);
         div.add(new AjaxEventBehavior("onclick") {
             protected void onEvent(AjaxRequestTarget target) {
                 System.out.println("ajax here!");
             }
         }
 
This behavior will be linked to the onclick javascript event of the div WebMarkupContainer represents, and so anytime a user clicks this div the onEvent(AjaxRequestTarget) of the behavior is invoked.

Since:
1.2
Author:
Igor Vaynberg (ivaynberg)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
 
Fields inherited from interface org.apache.wicket.behavior.IBehaviorListener
INTERFACE
 
Constructor Summary
AjaxEventBehavior(java.lang.String event)
          Construct.
 
Method Summary
protected  java.lang.CharSequence generateCallbackScript(java.lang.CharSequence partialCall)
          Returns javascript that performs an ajax callback to this behavior.
 java.lang.String getEvent()
           
protected  java.lang.CharSequence getEventHandler()
           
protected  void onCheckEvent(java.lang.String event)
           
protected  void onComponentTag(ComponentTag tag)
          Called any time a component that has this handler registered is rendering the component tag.
protected abstract  void onEvent(AjaxRequestTarget target)
          Listener method for the ajax event
protected  void respond(AjaxRequestTarget target)
           
 AjaxEventBehavior setThrottleDelay(Duration throttleDelay)
          Sets the throttle delay for this behavior.
 
Methods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, getAjaxCallDecorator, getCallbackScript, getCallbackScript, getChannelName, getFailureScript, getPreconditionScript, getSuccessScript, onBind, onRequest, renderHead, throttleScript
 
Methods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior
bind, getCallbackUrl, getCallbackUrl, getComponent, getImplementationId, getStatelessHint, onComponentRendered, onComponentTag, onRendered, onRenderHeadContribution, onRenderHeadInitContribution
 
Methods inherited from class org.apache.wicket.behavior.AbstractBehavior
afterRender, beforeRender, cleanup, detach, detachModel, exception, isEnabled, isTemporary, onException, rendered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AjaxEventBehavior

public AjaxEventBehavior(java.lang.String event)
Construct.

Parameters:
event - event this behavior will be attached to
Method Detail

setThrottleDelay

public final AjaxEventBehavior setThrottleDelay(Duration throttleDelay)
Sets the throttle delay for this behavior. Throttled behaviors only execute once within the given delay even though they are triggered multiple times.

For example, this is useful when attaching this behavior to the onkeypress event. It is not desirable to have an ajax call made every time the user types so we throttle that call to a desirable delay, such as once per second. This gives us a near real time ability to provide feedback without overloading the server with ajax calls.

Parameters:
throttleDelay - throttle delay
Returns:
this for chaining

onComponentTag

protected void onComponentTag(ComponentTag tag)
Description copied from class: AbstractAjaxBehavior
Called any time a component that has this handler registered is rendering the component tag. Use this method e.g. to bind to javascript event handlers of the tag

Overrides:
onComponentTag in class AbstractAjaxBehavior
Parameters:
tag - the tag that is rendered
See Also:
AbstractAjaxBehavior.onComponentTag(org.apache.wicket.markup.ComponentTag)

getEventHandler

protected java.lang.CharSequence getEventHandler()
Returns:
event handler

generateCallbackScript

protected java.lang.CharSequence generateCallbackScript(java.lang.CharSequence partialCall)
Description copied from class: AbstractDefaultAjaxBehavior
Returns javascript that performs an ajax callback to this behavior. The script is decorated by the ajax callback decorator from AbstractDefaultAjaxBehavior.getAjaxCallDecorator().

Overrides:
generateCallbackScript in class AbstractDefaultAjaxBehavior
Parameters:
partialCall - Javascript of a partial call to the function performing the actual ajax callback. Must be in format function(params, with signature function(params, onSuccessHandler, onFailureHandler. Example: wicketAjaxGet('callbackurl'
Returns:
script that performs ajax callback to this behavior

onCheckEvent

protected void onCheckEvent(java.lang.String event)
Parameters:
event -

getEvent

public final java.lang.String getEvent()
Returns:
event

respond

protected final void respond(AjaxRequestTarget target)
Specified by:
respond in class AbstractDefaultAjaxBehavior
Parameters:
target - The AJAX target
See Also:
AbstractDefaultAjaxBehavior.respond(org.apache.wicket.ajax.AjaxRequestTarget)

onEvent

protected abstract void onEvent(AjaxRequestTarget target)
Listener method for the ajax event

Parameters:
target -


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.