A script-enabled browser is required for this page to function properly.

Communicating with a JavaBean

At runtime, communication between the form and the JavaBean’s container takes place through these facilities:

CustomListener and CustomEvents

The form provides a CustomListener interface, and an associated CustomEvent class. In its initiation procedure at runtime, the form’s Handler registers a CustomListener with the JavaBean container/wrapper. Then, during execution, the JavaBean container/wrapper communicates with the form by sending custom events to it via that CustomListener. This follows the standard AWT event mechanism. (Your container/wrapper must extend VBean, which supplies the CustomListener and CustomEvents.)


   public Custominterface CustomListener extends EventListener {
     public void customActionPerformed(CustomEvent event); 
   } 
   public class CustomEvent extends java.util.EventObject { 
     public mEvent(Object source, ID name); 
     public string getName(); 
   }

Registering and Setting Properties

For elements in the container/wrapper to be known in the form, they must be registered. You register your events, properties, and methods in your container by calling ID.registerProperty.

When events, properties, and methods have been registered in the container, they can be known and accessed by those same names in the form.

Here is an example of an event registration:

private static final ID MOUSEPRESSED = ID.registerProperty("MousePressed");

The When-Custom-Item-Event Trigger

This trigger is used in the form to receive control and information from the JavaBean container during runtime. Forms registers a CustomListener with each bean container it instantiates. When the container dispatches a custom event during runtime, the listener is automatically activated and it fires the associated When-Custom-Item-Event trigger in the form. The CustomEvent contains the event name in its PropertyID.

When the When-Custom-Item-Event trigger is activated in the form, it can access the name of the event from the system variable System.Custom_Item_Event. The trigger can also can access properties set since the last time the trigger was executed. The system accumulates these in the system variable System.Custom_Item_Event_Parameters. It clears this variable when the trigger exits.

For example, assume the following event code in the container/wrapper:

 

public void mousePressed(MouseEvent event)
{
Integer xobj = new Integer(event.getX());
Integer yobj = new Integer(event.getY());
try
{
mHandler.setProperty(X_POS, xobj);
mHandler.setProperty(Y_POS, yobj);
}
CustomEvent ce = new CustomEvent(mHandler, MOUSEPRESSED);
dispatchCustomEvent(ce);
}

This mousePressed event could be handled in the form in a When-Custom-Item-Event trigger as follows:

 

BeanValListHdl := get_parameter_list(:SYSTEM.Custom_Item_Event_Parameters);
 EventName := :SYSTEM.Custom_Item_Event;
:event_name := EventName;
if (EventName = 'MousePressed') then
.
.

User-defined JavaBean properties are only accessible in the form from within this trigger. The client does not send user-defined properties to the server until the custom event is dispatched. These properties are available from the client, however, if the bean container's getProperty method supports them.

The Set_Custom_Property Built-in

You can set registered properties of the JavaBean from a Forms trigger by calling the Set_Custom_Property Built-in. Invoking this Built-in causes setProperty() to be called in the corresponding JavaBean container. The Built-in passes a value parameter of type String, Integer, or Boolean. If the name passed in the Built-in is not registered in the JavaBean container, the Built-in fails silently.


How to Add JavaBeans by Adding Your Own Java Code

Including a JavaBean and Custom Controls

Item Type Property

Implementation Class