The My Company Directory application displays a list of all current employee records in the directory. The records are displayed in a JTable (employeesTable) with sortable columns, including last name, first name, email, and employee ID. In order to get the records for the table, you need to bind the employeesTable to a data object that is returned by the sample Web service data source.
In order to get a local data object for the employeesTable to work with, you will use the visual editor to add a data source to your application. The data source connects to the sample Web service proxy and discovers the service methods available to your application. You will then choose the getLightEmployeeRecord service method that is made available from the data source. Finally, you will bind the employeesTable in your application to the fields that are returned in the row data object (lightEmployeeRecordRows).
You can create all of these data sources and data objects quickly and easily by using the Java visual editor's built-in binder classes. The visual editor provides a set of generic interfaces and classes that are generated into your project as you bind visual components to data factories. The binder classes are generated by default into a package named jve.generated. The visual editor provides the binder classes as a generic implementation that you can further customize and enhance to meet your application's needs. This tutorial demonstrates the power and flexibility of even a basic and simple use of the default binder classes.
For this tutorial, you will use a Web service data source, several types of data objects, and several types of binders in your application. When you add instances of these objects to your application, the visual editor adds the necessary classes into the jve.generated package in your project, where you could extend, replace, or rewrite the data binding logic. The Java visual editor provides visual support for the binding objects by showing on the free-form area of the design view the data objects, data sources, and binders that your application is using. The visual editor draws lines between visual components and the data objects and data sources to show the current bindings for any selected object.
The following diagram is a simple overview of how visual components, binders, data objects, and data sources interact. The application that you build in this tutorial illustrates a slightly more complex and creative use of the binders. This diagram does not represent exactly the binders, data objects, and data sources in the sample application that you are building.
In Figure 1, each visual component has its own binder that associates it with a data object or, in the case of the button, a data source. The binders for the text fields bind the field to a particular property of the data object. Both the row data object and the data object in this diagram get their data from direct calls to a service on the data source. The data object for the text fields uses a key value from the selected row in the table as its argument for calling Service2, which returns a full record that presumably includes more information about the selected row in the table. This full record, in turn, is used as the argument for the button's action binder when it calls Service3, which could be a method that updates the values entered in the fields. For more detailed explanations of the data objects, data binders, and data sources, follow the links provided earlier.
In order to work with the Web service running on a server, your Java application requires a Java proxy, or client, to interact with it. Using a WSDL file, you can generate a Java proxy into your Java project using the Web Service Client wizard. Your MyDirectory project includes the EmployeeDirectory.wsdl file that you will use to generate this proxy. After you generate the Java proxy, you can create a data source that represents the Web service and begin binding visual components.
To generate the Web service Java proxy in your project:
Because the employeesTable is the first visual component that you are binding in this application, you need to create a data source that points to the sample Web service proxy that you just added to your project. When you bind other visual components in later exercises, you will reuse this data source. In this step, you add the Web service data source and the lightEmployeeRecordRows data object.
Notice the changes to your project and application. During this lesson you added the Web service data source, a row data object, and a binder that binds the employeesTable to the row data object.
Now, when you run the My Company Directory application, the employees table is populated by the Web service with the existing employee records.