Class JQueryAjaxBehavior
- java.lang.Object
-
- org.apache.wicket.behavior.Behavior
-
- org.apache.wicket.behavior.AbstractAjaxBehavior
-
- org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
-
- com.googlecode.wicket.jquery.core.ajax.JQueryAjaxBehavior
-
- All Implemented Interfaces:
Serializable,IComponentAwareEventSink,IRequestListener,IComponentAwareHeaderContributor,IClusterable
- Direct Known Subclasses:
JQueryAjaxPostBehavior
public abstract class JQueryAjaxBehavior extends AbstractDefaultAjaxBehavior
Base class for implementing AJAX GET calls to aIJQueryAjaxAwaresource, which is usually aJQueryBehavior
Exampleinterface IMyJQueryListener { void onMyEvent(AjaxRequestTarget target); } public class MyJQueryLabel extends Label implements IJQueryWidget, IMyJQueryListener { private static final long serialVersionUID = 1L; public MyJQueryLabel(String id) { super(id); } // Events // protected void onInitialize() { super.onInitialize(); this.add(JQueryWidget.newWidgetBehavior(this)); } public void onMyEvent(AjaxRequestTarget target) { // do something here } public JQueryBehavior newWidgetBehavior(String selector) { return new MyJQueryBehavior(selector, "jquerymethod") { private static final long serialVersionUID = 1L; public void onMyEvent(AjaxRequestTarget target) { MyJQueryLabel.this.onMyEvent(target); } }; } static abstract class MyJQueryBehavior extends JQueryBehavior implements IJQueryAjaxAware, IMyJQueryListener { private static final long serialVersionUID = 1L; private JQueryAjaxBehavior onMyEventAjaxBehavior; public MyJQueryBehavior(String selector, String method) { super(selector, method); } public void bind(Component component) { super.bind(component); component.add(this.onMyEventAjaxBehavior = this.newJQueryAjaxBehavior(this)); } // Events // public void onConfigure(Component component) { this.setOption("jqueryevent", this.onMyEventAjaxBehavior.getCallbackFunction()); super.onConfigure(component); } public void onAjax(AjaxRequestTarget target, JQueryEvent event) { if (event instanceof MyEvent) { this.onMyEvent(target); } } // Factory // protected JQueryAjaxBehavior newJQueryAjaxBehavior(IJQueryAjaxAware source) { return new JQueryAjaxBehavior(source) { private static final long serialVersionUID = 1L; protected CallbackParameter[] getCallbackParameters() { return new CallbackParameter[] { CallbackParameter.context("event"), CallbackParameter.context("ui") }; } protected JQueryEvent newEvent() { return new MyEvent(); } }; } // Event objects // protected static class MyEvent extends JQueryEvent { } } }- Author:
- Sebastien Briquet - sebfz1
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
-
-
Constructor Summary
Constructors Constructor Description JQueryAjaxBehavior(IJQueryAjaxAware source)ConstructorJQueryAjaxBehavior(IJQueryAjaxAware source, Duration duration)Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringgetCallbackFunction()protected CallbackParameter[]getCallbackParameters()Gets theCallbackParametersthat *may* be passed toAbstractDefaultAjaxBehavior.getCallbackFunction(CallbackParameter...)
This is a convenience method that allows to defineCallbackParametersbefore the invocation ofAbstractDefaultAjaxBehavior.getCallbackFunction(CallbackParameter...).protected abstract JQueryEventnewEvent()Gets theJQueryEventto be broadcasted to theIJQueryAjaxAwaresource when the behavior will respondprotected voidrespond(AjaxRequestTarget target)protected voidupdateAjaxAttributes(AjaxRequestAttributes attributes)-
Methods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onBind, onMethodMismatch, onRequest, postprocessConfiguration, renderAjaxAttributes, renderAjaxAttributes, renderHead
-
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, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onConfigure, onEvent, onException, onRemove, onTag
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.IRequestListener
rendersPage
-
-
-
-
Constructor Detail
-
JQueryAjaxBehavior
public JQueryAjaxBehavior(IJQueryAjaxAware source)
Constructor- Parameters:
source-Behaviorto which the event - returned bynewEvent()- will be broadcasted.
-
JQueryAjaxBehavior
public JQueryAjaxBehavior(IJQueryAjaxAware source, Duration duration)
Constructor- Parameters:
source-Behaviorto which the event - returned bynewEvent()- will be broadcasted.duration-Duration. If different thanDuration#NONE, anThrottlingSettingswill be added with the specifiedDuration.
-
-
Method Detail
-
respond
protected void respond(AjaxRequestTarget target)
- Specified by:
respondin classAbstractDefaultAjaxBehavior
-
newEvent
protected abstract JQueryEvent newEvent()
Gets theJQueryEventto be broadcasted to theIJQueryAjaxAwaresource when the behavior will respond- Returns:
- the
JQueryEvent
-
updateAjaxAttributes
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
- Overrides:
updateAjaxAttributesin classAbstractDefaultAjaxBehavior
-
getCallbackParameters
protected CallbackParameter[] getCallbackParameters()
Gets theCallbackParametersthat *may* be passed toAbstractDefaultAjaxBehavior.getCallbackFunction(CallbackParameter...)
This is a convenience method that allows to defineCallbackParametersbefore the invocation ofAbstractDefaultAjaxBehavior.getCallbackFunction(CallbackParameter...).- Returns:
- an array of
CallbackParameter - See Also:
getCallbackFunction()
-
getCallbackFunction
public String getCallbackFunction()
CallsAbstractDefaultAjaxBehavior.getCallbackFunction(CallbackParameter...)by passingCallbackParametersfromgetCallbackParameters()- Returns:
- the javascript function.
-
-