Creating a New Timer Control

A Timer control notifies your application when a specified period of time has elapsed or when a specified time has been reached. Each Timer control is customized with a particular behavior. Timer controls are declared locally in an application's JWS file, rather than in a separate file.

This topic describes how to create a new Timer control and provides an example of the Timer control's declaration in a JWS file.

Creating a New Timer Control

You can create a new Timer control in any of the following types of files:

To create a new Timer control, follow these steps:

  1. Open the file to which you want to add the control in the WebLogic Workshop design environment.
  2. Display the Data Palette (View->Windows->Data Palette).
  3. On the Data Palette, click the Add drop-down, and choose Timer. The Insert Control - Insert Timer dialog opens.
  4. In the Variable name for this control field, type the name of the new control. The name you enter must be a valid Java identifier.
  5. In the timeout field, specify the amount of time you want to elapse before the timer fires the first time.
  6. If applicable, in the repeats-every field, specify the interval between firings after the Timer fires the first time.
  7. Choose whether or not you want to make this a control factory by selecting or clearing the Make this a control factory that can create multiple instances at runtime checkbox. For more information about control factories, see Control Factories: Managing Collections of Controls.
  8. Click Create.

When you create a Timer control, WebLogic Workshop imports the Timer control class, com.bea.control.TimerControl, into your source file.

Note that you cannot create a new Timer control in a Java Page Flow (JPF file) or a Java Server Page (JSP file), because the Timer control defines a callback, the onTimeout method, but page flow and JSP pages cannot accept callbacks. For more information on how to use Java controls from page flows, see Introduction to Asynchronous Java Controls.

Example: Timer Control Declarations

When you create a new Timer control, its declaration appears in the source file. The following code snippet is an example of what the declaration looks like:

import com.bea.control.TimerControl;
...
/**
 * @common:control
 * @jc:timer timeout="5 seconds" repeats-every="5 seconds"
 */
TimerControl delayTimer;

The actual attributes that are present on the @jc:timer annotation depend on the values you entered in the Insert Control - Insert Timer dialog.

The @common:control annotation informs WebLogic Workshop that the associated declaration is a control. Without this annotation, the control is not properly connected to supporting code and will not function.

For more information on the @common:control annotation, see @common:control annotation.

The @jc:timer annotation controls the behavior of the Timer control. All of the attributes of the @jc:timer annotation are optional and have default values.

For more information on the @jc:timer annotation, see @jc:timer annotation.

The Timer control, named myTimer in the example above, is declared as an instance of TimerControl. Timer controls are unusual in that you can instantiate the control class directly. Most other controls requires that you declare a subclass of the base class and then declare the new class.

Related Topics

Using WebLogic Built-In Controls

Timer Control

Using a Timer Control

Specifying Time on a Timer Control