In this step, you will create a new custom control. You will also insert a method into the control that calls a method on one of the controls you imported earlier.
In the Package Explorer view, right-click the ServicesWeb/src/controls
Click New > Custom Control.
In the New Control dialog, in the Control name box, enter MailingListControl.java, then click Finish.
Through the preceding steps, you should have created the following two Java files in
the controls folder:
MailingListControl.java — the control
MailingListControlImpl.java — the control
implementation file that implements MailingListControl.java.
These files contain only a default framework at this point. You will add
a method in the following steps.
In the Package Explorer view, double-click MailingListControlImpl.java.
In the source editor, right-click anywhere within the source code for
MailingListControlImpl.java and click Insert > Control.
In the Select Control dialog, select CustomerControl
- controls, then click OK.
Add the following import statement to support code you are about to add:
After the variable declaration for customerControl, add the following method:
public Customer getLocalCustomers()
Although you have created a new method in this class, the corresponding
abstract method definition does not yet exist in MailingListControl.java,
the interface that this class implements.
To correct this situation place the editor's cursor anywhere in the name
of the method (getLocalCustomers) and press Ctrl+1. Select Create in super type 'MailingListControl' and press Enter.
MailingListControl.java opens in the editor with
the new method definition in place.
Press Ctrl+Shift+S to save all of the edited files.
The getLocalCustomers method on this control uses the imported controls to query a sample database for all customers in a given state. In this example, we have hard-coded the state to be California. The data returned from the database is returned to the calling method as an array of Customer objects.
Click one of the following arrows to navigate through the tutorial: