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:
Serializable, IBehaviorListener, IComponentAwareEventSink, IRequestListener, IComponentAwareHeaderContributor, IClusterable
Direct Known Subclasses:
AbstractAjaxTimerBehavior, AjaxEventBehavior, AjaxNewWindowNotifyingBehavior

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  String findIndicatorId()
          Finds the markup id of the indicator.
protected  AjaxRequestAttributes getAttributes()
           
 CharSequence getCallbackFunction(CallbackParameter... extraParameters)
          Generates a javascript function that can take parameters and performs an AJAX call which includes these parameters.
 CharSequence getCallbackFunctionBody(CallbackParameter... extraParameters)
          Generates the body the callback function.
 CharSequence getCallbackScript()
           
protected  CharSequence getCallbackScript(Component component)
           
protected  AjaxChannel getChannel()
          Deprecated. Use AjaxRequestAttributes
protected  CharSequence getFailureScript()
          Deprecated. 
protected  CharSequence getPreconditionScript()
          Deprecated. Use AjaxRequestAttributes
protected  CharSequence getSuccessScript()
          Deprecated. 
protected  void onBind()
          Subclasses should call super.onBind()
 void onRequest()
          Called when a request to a behavior is received.
protected  void postprocessConfiguration(JSONObject attributesJson, Component component)
          Gives a chance to modify the JSON attributesJson that is going to be used as attributes for the Ajax call.
protected  CharSequence renderAjaxAttributes(Component component)
           { u: 'editable-label?6-1.IBehaviorListener.0-text1-label', // url m: 'POST', // method name.
protected  CharSequence renderAjaxAttributes(Component component, AjaxRequestAttributes attributes)
           
 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)
           
protected  void updateAjaxAttributes(AjaxRequestAttributes attributes)
          Gives a chance to the specializations to modify the attributes.
 
Methods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior
afterRender, bind, getCallbackUrl, getComponent, onComponentRendered, onComponentTag, onComponentTag, onUnbind, unbind
 
Methods inherited from class org.apache.wicket.behavior.Behavior
beforeRender, canCallListenerInterface, detach, getStatelessHint, isEnabled, isTemporary, onConfigure, onEvent, onException, onRemove
 
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.head.IHeaderResponse)

getAttributes

protected final AjaxRequestAttributes getAttributes()
Returns:
the Ajax settings for this behavior
Since:
6.0

updateAjaxAttributes

protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
Gives a chance to the specializations to modify the attributes.

Parameters:
attributes -
Since:
6.0

renderAjaxAttributes

protected final CharSequence renderAjaxAttributes(Component component)
                                {
                                        u: 'editable-label?6-1.IBehaviorListener.0-text1-label',  // url
                                        m: 'POST',          // method name. Default: 'GET'
                                        c: 'label7',        // component id (String) or window for page
                                        e: 'click',         // event name
                                        sh: [],             // list of success handlers
                                        fh: [],             // list of failure handlers
                                        pre: [],            // list of preconditions. If empty set default : Wicket.$(settings{c}) !== null
                                        ep: {},             // extra parameters
                                        async: true|false,  // asynchronous XHR or not
                                        ch: 'someName|d',   // AjaxChannel
                                        i: 'indicatorId',   // indicator component id
                                        ad: true,           // allow default
                                }
 

Parameters:
component - the component with that behavior
Returns:
the attributes as string in JSON format

renderAjaxAttributes

protected final CharSequence renderAjaxAttributes(Component component,
                                                  AjaxRequestAttributes attributes)
Parameters:
component -
attributes -
Returns:
the attributes as string in JSON format

postprocessConfiguration

protected void postprocessConfiguration(JSONObject attributesJson,
                                        Component component)
                                 throws JSONException
Gives a chance to modify the JSON attributesJson that is going to be used as attributes for the Ajax call.

Parameters:
attributesJson - the JSON object created by #renderAjaxAttributes()
component - the component with the attached Ajax behavior
Throws:
JSONException - thrown if an error occurs while modifying attributesJson argument

getCallbackScript

public CharSequence getCallbackScript()
Returns:
javascript that will generate an ajax GET request to this behavior with its assigned component

getCallbackScript

protected CharSequence getCallbackScript(Component component)
Parameters:
component - the component to use when generating the attributes
Returns:
script that can be used to execute this Ajax behavior.

getCallbackFunction

public CharSequence getCallbackFunction(CallbackParameter... extraParameters)
Generates a javascript function that can take parameters and performs an AJAX call which includes these parameters. The generated code looks like this:
 function(param1, param2) {
    var attrs = attrsJson;
    var params = {'param1': param1, 'param2': param2};
    attrs.ep = jQuery.extend(attrs.ep, params);
    Wicket.Ajax.ajax(attrs);
 }
 

Parameters:
extraParameters -
Returns:
A function that can be used as a callback function in javascript

getCallbackFunctionBody

public CharSequence getCallbackFunctionBody(CallbackParameter... extraParameters)
Generates the body the callback function. To embed this code directly into a piece of javascript, make sure any context parameters are available as local variables, global variables or within the closure.

Parameters:
extraParameters -
Returns:
The body of the callback function.

getPreconditionScript

@Deprecated
protected CharSequence getPreconditionScript()
Deprecated. Use AjaxRequestAttributes

Returns:
an optional javascript expression that determines whether the request will actually execute (in form of return XXX;);

getFailureScript

@Deprecated
protected CharSequence getFailureScript()
Deprecated. 

Returns:
javascript that will run when the ajax call finishes with an error status

getSuccessScript

@Deprecated
protected CharSequence getSuccessScript()
Deprecated. 

Returns:
javascript that will run when the ajax call finishes successfully

getChannel

@Deprecated
protected AjaxChannel getChannel()
Deprecated. Use AjaxRequestAttributes

Provides an AjaxChannel for this Behavior.

Returns:
an AjaxChannel - Defaults to null.

findIndicatorId

protected 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


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