Creating new data objects in the Java visual editor
In order to bind Java visual components, you need to first create a data object that can provide appropriate data for the visual component.
Because different types of visual components require different types of data, the Java visual editor provides different types of data objects. For example, a JTable requires an array of objects, so you need a row data object. A JTextField on the other hand typically only needs a single property in a data object, so you need a basic data object. Data objects can get their data directly from a data source, or they can get data indirectly from other data objects or factories.
There are two main ways that you can create a data object:
- Drop a data object from the palette onto the free-form area and configure it using the Properties view.
- Click the New Data Source Data Object button on the Bindings dialog while binding a visual component. Only data source data objects can be created using the dialogs. Data source data objects are objects that wrap a Java object that is created from a data source. To create a basic data object, drop it from the palette.
To use the New Data Source Data Object dialog to create a new data source data object:
- Open the New Data Source Data Object dialog:
- Open a Bindings dialog for a visual component by selecting it and clicking the Bind tab.
- Click the New Data Source Data Object button.
- In the Name field, type a name for the data object. You can skip this step and let the dialog suggest a name for the data object based on the data source service.
- In the Source type drop-down list, select one of the following types, corresponding to the type of data source that is providing the data object:
- EJB: Select this option if you are using (or are going to create) a data source based on an existing enterprise bean.
- Web Service: Select this option if you are using (or are going to create) a data source based on an existing Web service.
- Java Bean Factory: Select this option if you are using (or are going to create) a data source based on a basic Java bean factory.
- (Other types that you contribute to the Java visual editor that implement the IDataSource interface)
The Data source drop-down list includes all the data sources of the specified type that are defined in your application.
- In the Data source drop-down list, select the data source that you want to use to provide the new data object.
If no data sources exist, click the ... button next to the Data source field to define a new data source of the type specified:
- EJB: A wizard looks for existing EJB references in your project and helps you to define a new data source based on the EJB reference that you select.
Note: When you create an EJB data source, serviceLocatorMgr.jar is added to the project class path.
- Web Service: A dialog looks in your project for existing Web service clients, or proxies. If a proxy already exists, you can select the Web service and click Finish to add the data source. You can also click Add new Web service to start the Web Service Client wizard, which helps you define a new proxy for your project based on a WSDL document.
- Java Bean Factory: The Choose a Bean dialog box opens, where you can specify the Java bean factory class that you want to use as a data source.
- In the Source service list, select the method provided by the data source that returns the desired data object. The Source service list only lists services that return object types appropriate to the type of visual component that you are binding. For example, if you are binding a table, only services that return arrays are listed.
- If the selected service requires a parameter, select an object in the Argument drop-down list, and, if necessary, select the specific property to use for the parameter. For example, a service might require a java.lang.Integer as the parameter, so you might select another existing data object in your application that includes an ID property that is an integer.
Note: The OK button is only enabled if a compatible argument (or argument and property) is specified.
Restriction: Only services that take one or fewer parameters are supported by the provided binder classes. If you are working with a service that takes many parameters, you could create a wrapper service that takes an object containing all required arguments.- Click OK.
The new data object is created, and the visual editor displays an item on the free-form area to represent the new data object. The following screen shot shows an example data object on the free-form area of the visual editor:
Parent topic
Binding Java visual components to data with the visual editor