## Building a Custom Control

Java controls are reusable components you can use anywhere within a platform application. They provide a convenient way to incorporate access to resources and encapsulate business logic.

WebLogic Workshop includes a set of built-in Java controls, mostly designed to access resources, such as Enterprise Java Beans (EJBs) and databases, from within your application. For an example of how to use one, see Using a Built-In Control.

You can also create custom Java controls tailored to your project or application. Custom controls are based on the same framework that built-in controls are based. Unlike built-in controls, which give you access to an interface that extends the source, source files for custom controls are stored within the project and accessed directly from the locations in which they are stored. This arrangement enables you to separate and reuse the control code.

WebLogic Workshop makes it easy to create a custom control: click the target folder and choose File —> New —> Custom Java Control. The Custom Control Editor opens and displays a Java control source file. This file defines the implementation for your custom control. It can be identified by the string Impl that appears in its name, for example, JoinDBImpl.jcs. In addition, WebLogic Workshop automatically generates and maintains a Java class file that defines the public interface for the Java control—you never need to edit this file.

The Custom Control Editor is a graphical tool that enables you to design a custom control and create methods to expose its functionality, such as the JoinDB custom control shown in the following figure.

Custom Control Editor

The following table describes the custom control design tools shown in the previous figure.

Tools for Designing Custom Control Files

Callout # | Use this tool... | For these tasks...
--- | --- | ---
1 | Application Window | Create, view, and edit custom control files in your portal application projects. The names of custom control files end in .jcs.
2 | Design and Source Views | Design your custom control file in this area. Switch between the Design and Source code views, as required; changes made in one view are automatically reflected in the other.
3 | Palette Window | Add methods, callbacks, variables, and so on, by dragging components from the Palette window and dropping them onto the Design View canvas. The options available in the Palette window depend on the type of control you are building.
4 | Data Palette Window | Define instances of Java controls for use in the custom control.
6 | Property Editor Window | Set properties for the custom control component that is currently selected. You can select a custom control component by clicking on it in the Design View canvas or by selecting its name in the Document Structure window (described below).
7 | Document Structure Window | View a summary of the Java entities that comprise the control file (see Figure: Document Structure Window for a Custom Control). The summary includes the Java classes, methods and signatures, variables, and inner classes defined for the custom control. You can select a Java entity in the Document Structure window by clicking on it. When you select a method, it is selected in the Design View canvas and you can edit its properties in the Property Editor window. You can double-click on a Java entity to jump to its code location in Source View.

The following figure shows the Document Structure window for a custom control.

Document Structure Window for a Custom Control

To learn more about building custom controls:

- See Tutorial: Java Control in the WebLogic Workshop Help.
- See Building Custom Java Controls in the WebLogic Workshop Help.