Class: cWebTimer
Properties | Events | Methods | Index of Classes
The Web Framework timer control. Used to trigger timed events to be sent from the client back to the server.
Hierarchy
cObject > cWebBaseObject > cWebObject > cWebTimer
Show full hierarchy and direct subclasses
- cObject
- cWebBaseObject
- cWebObject
- cWebTimer
Library: Web Application Class Library
Package: cWebTimer.pkg
Description
Use the cWebTimer class to send timed events to the server. Timers are ideal for polling information from the server or for performing periodic actions, for example a self-refreshing dashboard that displays the latest sales information.
Use cTimer for Windows applications.
Sample
Object oEventAvailability is a cWebView
Set psCaption to "Event - Seats Available"
Object oInvt_DD is a Invt_DataDictionary
Procedure OnConstrain
Forward Send OnConstrain
Constrain Invt.On_Hand gt 0
End_Procedure
End_Object
Set Main_DD To oInvt_DD
Set Server To oInvt_DD
Object oWebTimer1 is a cWebTimer
Set piInterval to 15000
Procedure OnTimer
Send RefreshListFromDD to oEventList
End_Procedure
End_Object
Object oEventList is a cWebList
Set pbFillHeight to True
Set piOrdering to 3
Object oInvt_Description is a cWebColumn
Entry_Item Invt.Description
Set psCaption to "Event Name"
Set piWidth to 50
End_Object
Object oInvt_On_Hand is a cWebColumn
Entry_Item Invt.On_Hand
Set psCaption to "Seats Available"
Set piWidth to 20
End_Object
End_Object
Set pbServerOnShow to True
Procedure OnShow
Send Find of oInvt_DD FIRST_RECORD Index.3
End_Procedure
End_Object
The above example demonstrates a view that lists events and the number of seats available for each event. A cWebTimer object is used to refresh the list every 15-seconds.
Object Name
The Web Framework uniquely identifies each web object via a combination of the object hierarchy (object nesting), and object name. This means that web object names must be unique within their parent (i.e. each sibling web object must have a unique name).
Object Placement
Timer objects are usually placed within a cWebView or cWebModalDialog. By default, when a timer is placed within a view or dialog, it will only fire if that view is the currently active view. See Starting and Stopping Timers (below).
Starting and Stopping Timers
Set pbAutoStart to True to ensure that the timer starts automatically when the host view is shown. When used outside of a view, it starts on initialization. This property is True by default.
Set pbAutoStop to True to ensure that the timer stops automatically when a view is hidden. This property is True by default.
Set pbWaitForCall to True to ensure the timer is restarted after each timer event. Set to False to configure the timer to fire only one event, then stop.
Send Start to programmatically start the timer.
Send Stop to programmatically stop the timer.
OnTimer Event
Timer events can be handled on the server by writing DataFlex code. A timer event can also be handled on the client (browser) by writing JavaScript code. Writing a server-side DataFlex handler is the simplest way to handle timer events.
Write an OnTimer event handler to perform the required action each time the timer is fired.
To write a client-side button OnTimer handler using JavaScript, set the psClientOnTimer property to the name of the JavaScript function that will execute when the timer is fired.
Set pbServerOnTimer to False to prevent the OnTimer event from being sent to the server. By default, pbServerOnTimer is True.
Timer Interval
Set piInterval to specify the interval between the OnTimer events in milliseconds. By default, the interval is 2000 ms (2 sec).