Custom Java controls and several built-in control types allow the specification of callbacks. Callbacks provide a way for a control or a web service to asynchronously notify a client that an event has occurred.
A callback is a method signature that is defined by a resource like a control where the method implementation must be provided by the client. The client enables reception of a callback by implementing a callback handler.
A simple way to think of a callback is as an event that your code can respond to. When a Timer control fires, it is an event, and WebLogic Workshop calls the Timer control's onTimeout callback handler. The callback handler is a method like any other, except that your code does not control when it is called. The callback handler may be called by WebLogic Workshop or by code running in a client. In the case of a callback defined by a control, the application that's using the control is the client. So your application implements callback handlers for callbacks defined by controls, and you can write code in the callback handler to run when the event occurs.
For more information on callbacks and asynchrony, see Designing Asynchronous Interfaces.
A callback definition in a Java control may look like the following:
void onReportStatus(String status);
This declaration appears in the source code for the service or control that defines the callback. There's no code associated with the callback definition -- only the method signature, including the return type and any parameters.
It is common for callbacks to have names that begin with on because a callback represents an event and the callback handler in the client will be called on occurrence of the event. The name of this callback handler suggests that the handler will be invoked when the report status is provided by a client.
Your application is responsible for implementing the handler for a callback defined by a control. In Design view, a callback defined by a control is highlighted as a hyperlink; when you click on this link, the callback handler is created for you in your code. You can then add code to it to respond to the callback.
The following shows an example of a callback handler as it might appear in your application:
void exampleControl_onReportStatus(String status) { // add your code here to take appropriate action given the status of the report }
In WebLogic Workshop, callback handler names are determined by the name of the control instance and the name of the callback. In the example above, the control instance from which we wish to receive the callback is exampleControl. The full name of the callback handler, exampleControl_onReportStatus, is the control instance name followed by an underscore and the name of the callback.