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
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 the
onEvent(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 then getEvent()
should be overridden.
- Since:
- 1.2
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
-
Field Summary
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetEvent()
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 final 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 Details
-
AjaxEventBehavior
Construct.- Parameters:
event
- the event this behavior will be attached to
-
-
Method Details
-
renderHead
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:
-
updateAjaxAttributes
Description copied from class:AbstractDefaultAjaxBehavior
Gives a chance to the specializations to modify the attributes.- Overrides:
updateAjaxAttributes
in classAbstractDefaultAjaxBehavior
-
getEvent
- Returns:
- event the event this behavior is attached to
-
respond
- Specified by:
respond
in classAbstractDefaultAjaxBehavior
- Parameters:
target
- The AJAX target
-
onEvent
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
-