org.apache.wicket.ajax
Class AbstractDefaultAjaxBehavior

java.lang.Object
  extended by org.apache.wicket.behavior.Behavior
      extended by org.apache.wicket.behavior.AbstractAjaxBehavior
          extended by org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
All Implemented Interfaces:
java.io.Serializable, IBehaviorListener, IClusterable, IComponentAwareEventSink, IRequestListener, IComponentAwareHeaderContributor
Direct Known Subclasses:
AbstractAjaxTimerBehavior, AbstractAutoCompleteBehavior, AjaxEditableLabel.EditorAjaxBehavior, AjaxEventBehavior, AjaxFormChoiceComponentUpdatingBehavior, ModalWindow.CloseButtonBehavior

public abstract class AbstractDefaultAjaxBehavior
extends AbstractAjaxBehavior

The base class for Wicket's default AJAX implementation.

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

Field Summary
static ResourceReference INDICATOR
          reference to the default indicator gif file.
 
Fields inherited from interface org.apache.wicket.behavior.IBehaviorListener
INTERFACE
 
Constructor Summary
AbstractDefaultAjaxBehavior()
           
 
Method Summary
protected  java.lang.String findIndicatorId()
          Finds the markup id of the indicator.
protected  java.lang.CharSequence generateCallbackScript(java.lang.CharSequence partialCall)
          Returns javascript that performs an ajax callback to this behavior.
protected  IAjaxCallDecorator getAjaxCallDecorator()
           
protected  java.lang.CharSequence getCallbackScript()
           
protected  AjaxChannel getChannel()
          Provides an AjaxChannel for this Behavior.
protected  java.lang.String getChannelName()
          Deprecated. Use getChannel() instead
protected  java.lang.CharSequence getFailureScript()
           
protected  java.lang.CharSequence getPreconditionScript()
           
protected  java.lang.CharSequence getSuccessScript()
           
protected  void onBind()
          Subclasses should call super.onBind()
 void onRequest()
          Called when a request to a behavior is received.
 void renderHead(Component component, IHeaderResponse response)
          Render to the web response whatever the component wants to contribute to the head section.
protected abstract  void respond(AjaxRequestTarget target)
           
static java.lang.CharSequence throttleScript(java.lang.CharSequence script, java.lang.String throttleId, Duration throttleDelay)
          Wraps the provided javascript with a throttled block.
 
Methods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior
afterRender, bind, getCallbackUrl, getComponent, getStatelessHint, onComponentRendered, onComponentTag, onComponentTag
 
Methods inherited from class org.apache.wicket.behavior.Behavior
beforeRender, canCallListenerInterface, detach, isEnabled, isTemporary, onConfigure, onEvent, onException, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDICATOR

public static final ResourceReference INDICATOR
reference to the default indicator gif file.

Constructor Detail

AbstractDefaultAjaxBehavior

public AbstractDefaultAjaxBehavior()
Method Detail

onBind

protected void onBind()
Subclasses should call super.onBind()

Overrides:
onBind in class AbstractAjaxBehavior
See Also:
AbstractAjaxBehavior.onBind()

renderHead

public void renderHead(Component component,
                       IHeaderResponse response)
Description copied from class: Behavior
Render to the web response whatever the component wants to contribute to the head section.

Specified by:
renderHead in interface IComponentAwareHeaderContributor
Overrides:
renderHead in class Behavior
Parameters:
component - component which is contributing to the response. This parameter is here to give the component as the context for component-awares implementing this interface
response - Response object
See Also:
Behavior.renderHead(Component,org.apache.wicket.markup.html.IHeaderResponse)

getAjaxCallDecorator

protected IAjaxCallDecorator getAjaxCallDecorator()
Returns:
ajax call decorator used to decorate the call generated by this behavior or null for none

getCallbackScript

protected java.lang.CharSequence getCallbackScript()
Returns:
javascript that will generate an ajax GET request to this behavior

getPreconditionScript

protected java.lang.CharSequence getPreconditionScript()
Returns:
an optional javascript expression that determines whether the request will actually execute (in form of return XXX;);

getFailureScript

protected java.lang.CharSequence getFailureScript()
Returns:
javascript that will run when the ajax call finishes with an error status

getSuccessScript

protected java.lang.CharSequence getSuccessScript()
Returns:
javascript that will run when the ajax call finishes successfully

generateCallbackScript

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

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

getChannelName

@Deprecated
protected java.lang.String getChannelName()
Deprecated. Use getChannel() instead

Returns:
the name and the type of the channel to use when processing Ajax calls at the client side

getChannel

protected AjaxChannel getChannel()
Provides an AjaxChannel for this Behavior.

Returns:
an AjaxChannel - Defaults to null.

findIndicatorId

protected java.lang.String findIndicatorId()
Finds the markup id of the indicator. The default search order is: component, behavior, component's parent hierarchy.

Returns:
markup id or null if no indicator found

onRequest

public final void onRequest()
Description copied from interface: IBehaviorListener
Called when a request to a behavior is received.

See Also:
IBehaviorListener.onRequest()

respond

protected abstract void respond(AjaxRequestTarget target)
Parameters:
target - The AJAX target

throttleScript

public static java.lang.CharSequence throttleScript(java.lang.CharSequence script,
                                                    java.lang.String throttleId,
                                                    Duration throttleDelay)
Wraps the provided javascript with a throttled block. Throttled behaviors only execute once within the given delay even though they are triggered multiple times.

For example, this is useful when attaching an event 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:
script - javascript to be throttled
throttleId - the id of the throttle to be used. Usually this should remain constant for the same javascript block.
throttleDelay - time span within which the javascript block will only execute once
Returns:
wrapped javascript


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