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:
Serializable
,IComponentAwareEventSink
,IRequestListener
,IComponentAwareHeaderContributor
,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(Duration updateInterval)
Construct.AbstractAjaxTimerBehavior(Duration updateInterval)
Deprecated.Since Wicket 9 this constructor is deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
getTimerId()
Create an identifier for the JavaScript timer.Duration
getUpdateInterval()
Returns the update intervalboolean
isStopped()
void
onRemove(Component component)
Called to notify that the component is being removed from its parentstatic AbstractAjaxTimerBehavior
onTimer(Duration interval, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onTimer)
Creates anAbstractAjaxTimerBehavior
based on lambda expressionsprotected abstract void
onTimer(AjaxRequestTarget target)
Listener method for the AJAX timer event.protected void
onUnbind()
Called when the behavior is removed from its component.void
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)
void
restart(IPartialPageRequestHandler target)
Restart the timer.protected void
setUpdateInterval(Duration updateInterval)
Sets the update interval duration.protected boolean
shouldTrigger()
Decides whether the timer behavior should render its JavaScript to re-trigger it after the update interval.void
stop(IPartialPageRequestHandler target)
Stops the timer.-
Methods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onBind, onMethodMismatch, 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
-
-
-
-
Constructor Detail
-
AbstractAjaxTimerBehavior
@Deprecated public AbstractAjaxTimerBehavior(Duration updateInterval)
Deprecated.Since Wicket 9 this constructor is deprecated. It will be removed in Wicket 10. UseAbstractAjaxTimerBehavior(Duration)
insteadConstruct.- Parameters:
updateInterval
-Duration
between AJAX callbacks
-
AbstractAjaxTimerBehavior
public AbstractAjaxTimerBehavior(Duration updateInterval)
Construct.- Parameters:
updateInterval
-Duration
between AJAX callbacks
-
-
Method Detail
-
setUpdateInterval
protected final void setUpdateInterval(Duration updateInterval)
Sets the update interval duration. This method should only be called within theonTimer(AjaxRequestTarget)
method.- Parameters:
updateInterval
-
-
getUpdateInterval
public final Duration getUpdateInterval()
Returns the update interval- Returns:
- The update interval
-
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)
-
respond
protected final void respond(AjaxRequestTarget target)
- Specified by:
respond
in classAbstractDefaultAjaxBehavior
- Parameters:
target
- The AJAX target
-
shouldTrigger
protected boolean shouldTrigger()
Decides whether the timer behavior should render its JavaScript to re-trigger it after the update interval.- Returns:
true
if 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:
true
if has been stopped viastop(IPartialPageRequestHandler)
-
restart
public final void restart(IPartialPageRequestHandler target)
Restart the timer.- Parameters:
target
- may be null
-
getTimerId
protected 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:Behavior
Called to notify that the component is being removed from its parent
-
onUnbind
protected void onUnbind()
Description copied from class:AbstractAjaxBehavior
Called 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:
onUnbind
in classAbstractAjaxBehavior
-
onTimer
public static AbstractAjaxTimerBehavior onTimer(Duration interval, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onTimer)
Creates anAbstractAjaxTimerBehavior
based on lambda expressions- Parameters:
interval
- the interval the timeronTimer
- the consumer which accepts theAjaxRequestTarget
- Returns:
- the
AbstractAjaxTimerBehavior
-
-