Step 1: Create a Custom Control

In this step you will create a Utility project to house your control so they can be used by multiple modules in an application.

In this step, you will:

Start Workshop

If you haven't started Workshop yet, follow these steps: Start Workshop.

Create a New Workspace (Optional)

If you would like to execute the tutorial in a separate workspace follow these steps: Create a New Workspace.

Note: If you already have a workspace open, this will restart Workshop. Before beginning, you might want to launch help in standalone mode to avoid an interruption the restart could cause, then locate this topic in the new browser. See Using Help in a Standalone Mode for more information.

Configure WebLogic Server

This step only applies to user who do not have WebLogic Server installed. Users who already have WebLogic Server installed can skip to the next step.

In this step you will add a WebLogic Server domain for use with Workshop. This server domain contains runtime libraries required by the application.

Create a Utility Project

A utility project contains shared code that can be used across multiple different projects. For the sake of expediency we will create a bare Utility project without any associated application projects.

  1. Click File > New > Project.
  2. In the New Project dialog, expand J2EE, select Utility Project, then click Next.
  3. In the New Java Utility Module dialog, in the Project name field, enter MySharedControls, then click Next.
  4. Under Select Project Facets, select the Beehive Controls facet. (This facet must be selected because it contains ControlTestCase, an extension of junit.framework.TestCase, as well as the control validation and build libraries.)
  5. Click Finish.

You can safely ignore the errors that appear on the Problems view; these errors are expected and are caused by the fact that we have created a Utility project outside of any EAR project. The errors will not impede the tutorial to follow.

Note that you can avoid these errors by creating a utilty project along with the necessary EAR project by using the wizard: File > New > Project > Workshop Shop Quick Start Applications > WebLogic/Beehive Web Application.

Create a Custom Control

In this step you will create the control to be tested.

  1. On the Project Explorer view, expand the node MySharedControls, right-click the src folder and select New > Package.
  2. In the New Java Package dialog, in the Name field, enter sharedcontrols, and click Finish.
  3. On the Project Explorer view, right-click the sharedcontrols package and select New > Custom Control.
  4. In the New Control dialog, in the Control name field, enter EmployeeControl and click Finish.
  5. On the Project Explorer view, open the package sharedcontrols and double-click EmployeeControlImpl.java to open the file's source code. Edit the source code so it appears as follows. Code to add appears in red.
    package sharedcontrols;
      
    import org.apache.beehive.controls.api.bean.ControlImplementation;
    import java.io.Serializable;
     
    @ControlImplementation
    public class EmployeeControlImpl implements EmployeeControl, Serializable {
        private static final long serialVersionUID = 1L;
     
        public String[] getManagerNames() {
            return new String[]{"Jane","Bob","Amy"};
        }
    }
  6. Place the cursor inside the method name getManagerNames and press Ctrl+1.
    This will bring up an options menu.
    Double-click the option Create in super type 'EmployeeControl'.
    This will add the method signature to the control interface file EmployeeControl.java.

  7. Press Ctrl+Shift+S to save your work.

Related Topics

Testing Controls

Click one of the following arrows to navigate through the tutorial:


Still need help? Post a question on the Workshop newsgroup.