< Day Day Up > |
As you saw in Chapter 3, "WebLogic Workshop Application Development Basics," controls are specially annotated Java objects. As with any Java object, controls have a well-defined life cycle. They are created, perform their function, and are then destroyed . Controls differ from other objects in that you can catch life cycle events at various stages and perform work. Figure 8.1 shows the minimum life cycle events of all controls. Table 8.1 describes the details of each life cycle method. Other control types, such as asynchronous controls, add other events. Every control has an associated Context object. Figure 8.1. The control life cycle.
State 1: Looking at the control life cycle, you can see that controls start off in state 1, which is the state that exists before a control has been instantiated . As required by the application, WebLogic Workshop then creates an instance of the control, and the developer-coded onCreate() method is called. After an in-memory instance of the control exists, any child or encapsulated controls are created. Encapsulated controls are any controls that the control might use to get its job done. State 2: In state 2, a control is ready for use. All child controls have been instantiated and are ready. A control moves from state 2 to state 3 when the first developer-written business method is called. However, specialized initialization code might need to be executed. Developers can add this specialized code in the onAcquire() method. State 3: Controls stay in state 3 while business methods are executed. When the control is no longer needed, it moves to state 4, but not without first calling the onRelease() method, which can release any resources obtained in onAcquire() . State 4: State 4 is then reached and the control instance can be destroyed normally. Table 8.1. Control Life Cycle Event Callback Methods
You take advantage of life cycle events by adding a Context object to your custom Java control and then adding handler methods, such as onCreate() , onAcquire() , and onRelease() . The shaded portion of the following code shows the definition of the required Context object: public class LifeCycleImpl implements LifeCycle, ControlSource{ static final long serialVersionUID = 1L; /** * @common:context */ com.bea.control.ControlContext context; To handle life cycle events, you write handler methods specific to the event being handled. The following code shows adding an onCreate() handler: public void context_onCreate() { // your code here... }
Handler methods are actually callbacks to com.bea.control.ControlContext instances. To implement them, add the instance variable name to the beginning of the method. In the onCreate() example, using the context variable, you write handlers by adding context to the handler method name ”in this case, context_onCreate() . Refer back to Table 8.1 to see the method signature of the most important life cycle handler methods. |
< Day Day Up > |