How Do I: Begin a New Custom Java Control?

You can use custom controls to enclose business logic in a way that exposes a simple interface to developers. Java controls can provide ideal places for code that is used by several parts of a project, removing the necessity to duplicate code.

You can create a Java control for use within the same project as the code using it; for more information, see How Do I: Create and Use a Java Control Within an Existing Project? You can also develop your control code in a control project; see How Do I: Create and Use a Java Control Within a Control Project?

For an introduction to Java controls, see Tutorial: Java Control.

To Create Source Files for a Java Control

  1. Locate the folder in which you want to store your Java control source code.

    It may be a good idea to create a folder specifically for your control. This will help to keep your project structure more intuitive if you begin adding files that your new control requires, such as JCX files for nested controls. The folder you create will be part of the control's package name. Note that you cannot create the control in the root of a project — it must be in a subfolder.

  2. Right-click the folder you chose, then choose New-->Custom Java Control.
  3. In the New File dialog, in the left-hand pane, select All.
  4. In the right-hand pane, select Custom Java Control.
  5. In the File name field, enter a name for your new control source (JCS) file. Be sure to append "Impl" to the file name, preceding the JCS extension.

    The JCS file will contain your control's implementation class, which is why it requires an "Impl" ending. Note that WebLogic Workshop will preserve the extension as you type.

  6. Click Create.

    WebLogic Workshop creates the JCS file and displays it in Design View. It also creates a JAVA file without the "Impl" ending for your control's public interface. As you build your control, you work in the JCS file, adding code for the control's logic. As you do, WebLogic Workshop updates the JAVA file code to reflect changes to the control's public interface. In other words, you never have to edit the JAVA file manually.

    With your new control, you can:

Samples

For samples of Java controls whose source is kept locally with the source code from which the control is used, see the WebService project in the SamplesApp installed with WebLogic Workshop. For samples of controls in their own control project, see the ControlProject provided with the same application.

Related Topics

Getting Started with Java Controls

Tutorial: Java Control