timer

timer facet is designed to run UI code at specified time intervals.

The timer action is initiated from the browser as a user request and its handler can update UI components. The timer stops working when the view it was created for is closed.

Basic Usage

Add timer to the facets element of the view XML descriptor:

<facets>
    <timer id="timer" delay="3000" autostart="true" repeating="true"/>
</facets>

Create TimerActionEvent handler:

@Autowired
private Notifications notifications;

@Subscribe("timer")
public void onTimerTimerAction(final Timer.TimerActionEvent event) {
    notifications.show("Timer action");
}

The handler will be invoked every 3 seconds after the view is opened.

Attributes

timer is defined in the facets element of the view XML descriptor and has the following attributes:

delay

Required attribute. Defines timer interval in milliseconds.

autostart

Optional attribute. The default value is false, which means that the timer will start only when its start() method is invoked. When it is set to true, the timer starts immediately after the view opening.

repeating

Optional attribute. Turns on repeated executions of the timer. If the attribute is set to true, the timer runs in cycles at equal intervals defined in the delay attribute. Otherwise, the timer runs only once after the timeout specified in the delay attribute after the timer start.

Handlers

To generate a handler stub in Jmix Studio, use the Handlers tab of the Jmix UI inspector panel or the Generate Handler action available in the top panel of the view class and through the CodeGenerate menu (Alt+Insert / Cmd+N).

TimerActionEvent

TimerActionEvent is triggered after the specified time interval in the delay attribute has passed since the timer started. If the repeating attribute is set to true, this event is sent periodically, until the timer is stopped.

To register the event handler programmatically, use the addTimerActionListener() method of the facet.

TimerStopEvent

TimerStopEvent is sent when the timer is stopped by invoking the stop() method of the facet.

To register the event handler programmatically, use the addTimerStopListener() method of the facet.