Creating listener classes

The Listener wizard enables you to create Java™ listener classes for various Java EE listener types that are related to servlet context and session events and attributes.

Procedure

  1. Open the Web perspective and from the Enterprise Explorer, right-click on your web project and select New > Listener.
    The Create Listener wizard appears.
  2. Specify a listener class. To use an existing class, select the appropriate check box and then use the Browse button to locate the class. Otherwise, supply the following information
    • The folder where the listener class is placed
    • The Java package that the class belongs to (it is added into a default package if you do not specify one)
    • The class name of the listener.
      Note: You should place the listener in the Java source folder.
    • The superclass for the listener class. A listener that is created by this wizard can have Object, or any class that has Object in its hierarchy, as its superclass. Click Browse to choose from the available superclasses.
  3. Click Next.
  4. Select the application lifecycle events to listen to. You must select at least one of the application lifecycle listeners.
  5. Click Next.
  6. Select a modifier to specify whether your listener classes are public, abstract, or final. (Classes cannot be both abstract and final.)
  7. You can also add additional interfaces to implement in addition to the default interfaces. Click Add to open the Interface Selection dialog. In this dialog, as you type the name of the interface that you are interested in adding in the Choose interfaces field, the list of available interfaces listed in the Matching types list box updates dynamically to display only the interfaces that match the pattern. Choose an interface to see the Qualifier and click Add. Click OK when you are finished.
  8. Choose which method stub you want to create.
    The Inherited abstract methods and Constructors from superclass options add stubs for inherited abstract methods and superclass constructors that must be implemented (unless you intend to create an abstract listener). One method with the Inherited abstract methods option must be created for the class not to be abstract.
  9. Click Finish.

Results

The listener class that you created appears under the Listener icon.