Package org.apache.wicket.ajax
Class AjaxEventBehavior
- java.lang.Object
-
- org.apache.wicket.behavior.Behavior
-
- org.apache.wicket.behavior.AbstractAjaxBehavior
-
- org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
-
- org.apache.wicket.ajax.AjaxEventBehavior
-
- All Implemented Interfaces:
Serializable
,IComponentAwareEventSink
,IRequestListener
,IComponentAwareHeaderContributor
,IClusterable
- Direct Known Subclasses:
AjaxEditableLabel.LabelAjaxBehavior
,AjaxFileDropBehavior
,AjaxFormComponentUpdatingBehavior
,AjaxFormSubmitBehavior
,AjaxPagingNavigationBehavior
,AjaxPreventSubmitBehavior
public abstract class AjaxEventBehavior extends AbstractDefaultAjaxBehavior
An ajax behavior that is attached to a certain client-side (usually javascript) event, such as click, change, keydown, etc.Example:
WebMarkupContainer div=new WebMarkupContainer(...); div.setOutputMarkupId(true); div.add(new AjaxEventBehavior("click") { protected void onEvent(AjaxRequestTarget target) { System.out.println("ajax here!"); } }
This behavior will be linked to the click javascript event of the div WebMarkupContainer represents, and so anytime a user clicks this div theonEvent(AjaxRequestTarget)
of the behavior is invoked.Note:
getEvent()
method cuts any on prefix from the given event name(s). This is being done for easier migration of applications coming from Wicket 1.5.x where Wicket used inline attributes like 'onclick=...'. If the application needs to use custom events with names starting with on thengetEvent()
should be overridden.- Since:
- 1.2
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
onEvent(AjaxRequestTarget)
, Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
-
-
Constructor Summary
Constructors Constructor Description AjaxEventBehavior(String event)
Construct.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
getEvent()
static AjaxEventBehavior
onEvent(String eventName, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onEvent)
Creates anAjaxEventBehavior
based on lambda expressionsprotected abstract void
onEvent(AjaxRequestTarget target)
Listener method for the ajax eventvoid
renderHead(Component component, IHeaderResponse response)
Render to the web response whatever the component wants to contribute to the head section.protected 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.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onBind, onMethodMismatch, onRequest, postprocessConfiguration, renderAjaxAttributes, renderAjaxAttributes
-
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
-
AjaxEventBehavior
public AjaxEventBehavior(String event)
Construct.- Parameters:
event
- the event this behavior will be attached to
-
-
Method Detail
-
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 interfaceIComponentAwareHeaderContributor
- Overrides:
renderHead
in classAbstractDefaultAjaxBehavior
- 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 interfaceresponse
- Response object- See Also:
Behavior.renderHead(Component, org.apache.wicket.markup.head.IHeaderResponse)
-
updateAjaxAttributes
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
Description copied from class:AbstractDefaultAjaxBehavior
Gives a chance to the specializations to modify the attributes.- Overrides:
updateAjaxAttributes
in classAbstractDefaultAjaxBehavior
-
respond
protected final void respond(AjaxRequestTarget target)
- Specified by:
respond
in classAbstractDefaultAjaxBehavior
- Parameters:
target
- The AJAX target
-
onEvent
protected abstract void onEvent(AjaxRequestTarget target)
Listener method for the ajax event- Parameters:
target
- the current request handler
-
onEvent
public static AjaxEventBehavior onEvent(String eventName, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onEvent)
Creates anAjaxEventBehavior
based on lambda expressions- Parameters:
eventName
- the event nameonEvent
- theSerializableConsumer
which accepts theAjaxRequestTarget
- Returns:
- the
AjaxEventBehavior
-
-