Application Techniques

Adding a Listener to a Form Control

How to add an event listener to a control on a form.

About this technique



Java Client Techniques> General techniques for controls


You'll learn about:

You can run this technique code from:

NOTE   First make sure that database is running on your localhost SilverStream Server

Related reading

For another example using listeners, see Obtaining the Control with Focus

The form frmListeners has code that adds AgiRowSetListener for the agData control. AgiRowSetListener responds to changes in data. The input fields on the form are bound to agData, so after the user changes a value in an input field, RowSet events are generated.

The three basic steps described below apply to any listener. When you use the Programming Editor menu to add the interface, SilverStream automatically generates stubs for individual events so you don't have to worry about whether you've implemented the interface completely.

Adding a listener   Top of page

To add a listener:

  1. Specify that your form implements the listener interface.

    In the Programming Editor, select File -> Java Interfaces to add the listener interface. Use the Help system to find out the fully qualified package for the interface. In frmListeners, the interface being added is com.sssw.rt.event.AgiRowSetListener.

    Be sure to check Create stubs for interface methods.

  2. Write code that adds the form as a listener to the control.

    In the FormActivate event, after SilverStream has instantiated the controls, add the listener to the appropriate data control.

    For example, in frmListeners, this code adds the RowSetListener to the agData control. The keyword this refers to the form:

  3. Write code for any of the listener event stubs that SilverStream added to the form.

    For example, in frmListeners, there is code behind the rowDataChanged event. To see the code in action, change a field value and tab off the field.

      agDialog.showMessage("Event rowDataChanged", 
         "The data has changed for field:  "  
           + agoPropertyChangeEvent0.getPropertyName()  
           + "\r\nOld Value was:  "  
           + agoPropertyChangeEvent0.getOldValue()  
           + "\r\nNew Value is:   "  
           + agoPropertyChangeEvent0.getNewValue()); 

Copyright © 2000, SilverStream Software, Inc. All rights reserved.