Package org.apache.wicket.ajax
Class AbstractAjaxTimerBehavior
- java.lang.Object
-
- org.apache.wicket.behavior.Behavior
-
- org.apache.wicket.behavior.AbstractAjaxBehavior
-
- org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
-
- org.apache.wicket.ajax.AbstractAjaxTimerBehavior
-
- All Implemented Interfaces:
java.io.Serializable,IComponentAwareEventSink,IRequestListener,IComponentAwareHeaderContributor,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
AjaxClientInfoBehavior,AjaxSelfUpdatingTimerBehavior
public abstract class AbstractAjaxTimerBehavior extends AbstractDefaultAjaxBehavior
A behavior that generates an AJAX update callback at a regular interval.- Since:
- 1.2
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
onTimer(AjaxRequestTarget),restart(IPartialPageRequestHandler),stop(IPartialPageRequestHandler), Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
-
-
Constructor Summary
Constructors Constructor Description AbstractAjaxTimerBehavior(org.apache.wicket.util.time.Duration updateInterval)Construct.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringgetTimerId()Create an identifier for the JavaScript timer.org.apache.wicket.util.time.DurationgetUpdateInterval()Returns the update intervalbooleanisStopped()voidonRemove(Component component)Called to notify that the component is being removed from its parentprotected abstract voidonTimer(AjaxRequestTarget target)Listener method for the AJAX timer event.static AbstractAjaxTimerBehavioronTimer(org.apache.wicket.util.time.Duration interval, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onTimer)Creates anAbstractAjaxTimerBehaviorbased on lambda expressionsprotected voidonUnbind()Called when the behavior is removed from its component.voidrenderHead(Component component, IHeaderResponse response)Render to the web response whatever the component wants to contribute to the head section.protected voidrespond(AjaxRequestTarget target)voidrestart(IPartialPageRequestHandler target)Restart the timer.protected voidsetUpdateInterval(org.apache.wicket.util.time.Duration updateInterval)Sets the update interval duration.protected booleanshouldTrigger()Decides whether the timer behavior should render its JavaScript to re-trigger it after the update interval.voidstop(IPartialPageRequestHandler target)Stops the timer.-
Methods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onBind, onRequest, postprocessConfiguration, renderAjaxAttributes, renderAjaxAttributes, updateAjaxAttributes
-
Methods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior
afterRender, bind, getCallbackUrl, getComponent, onComponentRendered, onComponentTag, onComponentTag, unbind
-
Methods inherited from class org.apache.wicket.behavior.Behavior
beforeRender, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onConfigure, onEvent, onException, 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
-
-
-
-
Method Detail
-
setUpdateInterval
protected final void setUpdateInterval(org.apache.wicket.util.time.Duration updateInterval)
Sets the update interval duration. This method should only be called within theonTimer(AjaxRequestTarget)method.- Parameters:
updateInterval-
-
getUpdateInterval
public final org.apache.wicket.util.time.Duration getUpdateInterval()
Returns the update interval- Returns:
- The update interval
-
renderHead
public void renderHead(Component component, IHeaderResponse response)
Description copied from class:BehaviorRender to the web response whatever the component wants to contribute to the head section.- Specified by:
renderHeadin interfaceIComponentAwareHeaderContributor- Overrides:
renderHeadin 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)
-
respond
protected final void respond(AjaxRequestTarget target)
- Specified by:
respondin classAbstractDefaultAjaxBehavior- Parameters:
target- The AJAX target- See Also:
AbstractDefaultAjaxBehavior.respond(AjaxRequestTarget)
-
shouldTrigger
protected boolean shouldTrigger()
Decides whether the timer behavior should render its JavaScript to re-trigger it after the update interval.- Returns:
trueif the behavior is not stopped, it is enabled and still attached to any component in the page or to the page itself
-
onTimer
protected abstract void onTimer(AjaxRequestTarget target)
Listener method for the AJAX timer event.- Parameters:
target- The request target
-
isStopped
public final boolean isStopped()
- Returns:
trueif has been stopped viastop(IPartialPageRequestHandler)
-
restart
public final void restart(IPartialPageRequestHandler target)
Restart the timer.- Parameters:
target- may be null
-
getTimerId
protected java.lang.String getTimerId()
Create an identifier for the JavaScript timer.Note: The identifier must not change as long as this behavior is attached to a component!
- Returns:
- creates an id based on
Component.getMarkupId()andComponent.getBehaviorById(int)by default
-
stop
public final void stop(IPartialPageRequestHandler target)
Stops the timer.- Parameters:
target- may be null
-
onRemove
public void onRemove(Component component)
Description copied from class:BehaviorCalled to notify that the component is being removed from its parent
-
onUnbind
protected void onUnbind()
Description copied from class:AbstractAjaxBehaviorCalled when the behavior is removed from its component. The bound host component is still available through AbstractAjaxBehavior.getComponent(). The relation to it will be removed right after the finish of the execution of this method.- Overrides:
onUnbindin classAbstractAjaxBehavior
-
onTimer
public static AbstractAjaxTimerBehavior onTimer(org.apache.wicket.util.time.Duration interval, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onTimer)
Creates anAbstractAjaxTimerBehaviorbased on lambda expressions- Parameters:
interval- the interval the timeronTimer- the consumer which accepts theAjaxRequestTarget- Returns:
- the
AbstractAjaxTimerBehavior
-
-