Data binders overview

The Java visual editor provides a generic framework of interfaces and classes that help you to bind visual components to data sources such as enterprise bean, Java Bean factories, or Web services.

A visual component, like a table or a text field, needs a data source from which to pull data, and potentially to push data to. The Java visual editor provides three types of helper classes that can be generated into your project to enable simple and quick binding of visual components with data from a data source. The goal of these helper classes is not to provide a runtime framework for binding data to visual components, but rather to provide a quick-start to the visual development of client applications.

The three types of helper classes are data sources, data objects, and binders, each of which are discussed in more detail below. While the visual editor generates Swing-specific binder classes for the different Swing components supported, the data source and data object classes are completely independent of the visual components, allowing for possible future support of other widget libraries.

See the API documentation for the binder classes.

To learn about using the Java visual editor binders to connect to a data source, do the following tutorial:

Tutorial: Build a rich Java client that uses a Web service.

The following list describes some of the benefits of the binder classes that are generated and instantiated by the Java visual editor when you bind visual components:

As you bind visual components to data sources and data objects, binder code is generated as needed into your project source directory. By default, the generated classes are added to a jve.generated package in your project. You then have the freedom to extend, replace, or rewrite the data binding logic. The Java visual editor provides will provide visual support for data objects, data sources, and binders that correctly implement the provided interfaces.

Figure 1. A high-level overview of how the Java visual editor binds visual components to data objects and data sources

Diagram illustrating relationship between visual components, binders, data objects, and data sources as used in the Java visual editor

This diagram illustrates the following main parts of the Java visual editor process for binding visual components to data:
Data Sources
Data Sources on the Visual Editor Palette

A data source represents a data factory. It can be based on an EJB session bean, a Web service, a Java Bean factory, or anything that implements the IDataSource interface. A properly configured data source in the visual editor returns the set of available services from the actual data factory, making them available to the application.

A data source can be viewed as a factory for a facade. The data source provides configuration properties that allow the instantiation and initialization of a data source facade. The facade is a class that provides a set of methods that might create data objects from the back end or provide some other business function. During run time, the getDataSource() interface is used to get an instance of the facade. It is up to the data source implementer to ensure that the facade is instantiated properly. For example, an EJB Data Source calls the home interface to create the designated session bean before a getDataSource() is called. The getType() must return the type (Class) of the facade class. This API is called in design time, mainly for method introspection.

The Java visual editor provides default support for the following types of data sources, which implement the IDataSource interface:
EJB Data Source Data Sources on the Visual Editor Palette
An EJB Data Source provides an easy way for you to manage a connection to an enterprise bean to make the bean's services available as methods for your application to use.
Note: When you create an EJB data source, serviceLocatorMgr.jar is added to the project class path.
Web Service Data Source Data Sources on the Visual Editor Palette
A Web Service Data Source is used to configure a connection to a Web service proxy. This data source is configured by specifying the fully-qualified class name of the Locator class of the client proxy and the get service method within the Locator class.
Java Bean Data Source Data Sources on the Visual Editor Palette
A Java Bean Data Source uses a null constructor to instantiate a Java Bean factory. The bean's public methods are then available for use as service methods.
Data Objects
Data Objects on the Visual Editor Palette

A Data Object wraps a Java Object to manage it and provide event change support for it. The target object is accessible via the getObject() method on the IBoundObject interface.

There are several types of data objects implemented by the Java visual editor and available in the palette:

Data Source Data Object Data Source Data Object icon
A Data Source Data Object gets its data directly by invoking a service (method) on a data source. It requires you to specify the data source and the specific service on the data source that will provide the data. If the service takes a parameter, the service argument can be defined in the data source data object.

In Figure 1, the text fields are bound to properties in a Data Source Data Object that represents a data object that is returned by a call to Service2(param). In this release, only services that take one or fewer arguments are supported by the helper classes. As a workaround, you could wrap a set of arguments in another service.

Java Bean Data Object Java Bean Data Object icon
A Java Bean data object creates the Java object by using a null constructor provided by a Java bean factory. To define a Java Bean Data Object, you specify the Java Bean factory and the property in the factory that provides the null constructor for the Java Object.
Basic Data Object Basic Data Object icon
A Basic Data Object represents a single data object that is retrieved directly from another data object. To configure a basic data object, you simply specify the source object and, optionally, a property in the source object.
Data Source Row Object Data Source Row Object icon
A Data Source Row Object represents rows of objects (an array of objects) that are retrieved by a service call on a Data Source. A Data Source Row Object Is typically bound to a table.

In the earlier figure, the visual table is bound to a Data Source Row Object that represents an array of data objects returned by calling Service1 on the data source. The columns in the table are mapped to fields in the Data Source Row Object.

Binders
Swing Binders on the Visual Editor Palette
Binders are meta-objects that bind visual components to a data object or a data source. There is a one-to-one relationship between a visual component and its binder. There is a one-to-many relationship between a data object and the binders that interact with it. In other words, more than one visual component can be bound to a given data object, but each visual component requires its own binder.
Row Table Binder Row Table Binder icon
A Row Table Binder is a meta-object that is used to bind a visual table to an array of elements. The binder holds information such as which columns to list, the column headers, and an optional filter. The table binder also implements a basic data object (IDataObject interface) that represents the selected object on the visual table associated with the Row Table Binder. In other words, the selected row in the table is made available as a basic data object.

Figure 1 shows that the Row Table Binder listens for the selected row in the visual table and provides the basic data object for that row. That basic data object is then used as a parameter for Service2(param) to return a Data Source Data Object. The text fields in Figure 1 are bound to this Data Source Data Object.

Object Table Binder Object Table Binder icon
An Object Table Binder binds a table to an array property of another IDataObject rather than to a source service.

It is similar to the Row Table Binder, which gets its row data directly from a service call on a data source.

Text Binder Text Binder icon
A text binder contains a String text representation of a bound property of a data object. This binder is used to bind visual text fields to properties on data objects.

In Figure 1, Text Binders bind the visual text fields to properties in the Data Source Data Object that is returned by Service2(param). The parameter for Service2 in Figure 1 is collected from the selected row (probably a key field such as an ID) in the table. In this example, Service2 presumably returns more properties about the selected row in the visual table. For example, the visual table could list all employees, with last name and employee ID. The employee ID of the selected row is used as the parameter for Service2, which might return a full record for the employee, including the employee's salary. A text field could then be bound to the salary property in the data source data object returned by Service2.

Action Binder Action Binder icon
An action binder is used to bind a button directly to a specific service (method) available in the data source. The action binder also includes event listeners and fields that can control the state and behavior of the bound visual component. The action binder also provides an ActionBinderListener support for beforeActionPerformed and afterActionPerformed call-backs.

The Java visual editor supports binding JButtons to actions. When a button is bound to an action binder, the action binder can automatically change the button's enabled state when the arguments for the action change. For example, an action binder that invokes a service call could change the enabled state of a button when the parameters for that service call change.

In Figure 1, for example, the action binder for the button uses as its parameter the same data object that the text fields are bound to. So, if the text in the text fields change, the action binder for the button detects that the data object has changed and the action binder could tell the button to become enabled. Then, if the button were clicked, the action binder would take the new data object, with the changed values in the text fields, and invoke Service3(param) on the data source.

Text Filter Binder Text Filter Binder
A filter binder provides a simple mechanism for filtering the rows in a table based on text input in a text field. In the filter binder, you set the visual text field that will be used for text input, and you set the property (table column) on the row data object that will be filtered.

In Figure 1, a Text Filter Binder binds a text field to a particular column in the table.

Again, it is important to note that the generated classes and interfaces are simply a quick and easy way to get you started with binding visual components to data objects and services. The binders generated by the Java visual editor are not meant to be a framework, but are rather a generic, default implementation that works properly with the Java visual editor. You can enhance and customize the classes and interfaces in the generated package to meet the particular needs of your application and data source. If you do enhance the classes, the visual editor will still provide visual support for them as long as they correctly implement the provided interfaces.


Feedback