[Home] [Contents] [Index] [Javadoc] | ![]() [Frames] [No Frames] |
[Previous] [Next] |
Determining Which Technique to Use
Creating a New Field Component (Using an IDE)
Creating a New Field Component (Programmatically)
Data Binding
JClass Field offers several options when it comes to modifying properties. The choice of technique is a personal preference; however, the following two sections illustrate some important points to consider when deciding which technique to use.
JClass Field can be used with a Java Integrated Development Environment (IDE), and its properties can be manipulated at design time. Consult the IDE documentation for details on how to load third-party Bean components into the IDE. To modify properties of the component in an IDE, you simply drag the component onto the form. All you have to do then, is to edit the properties exposed by the Bean and the properties in the DataProperties editor. You can use many of Field's default properties "as is" and set the few that are specific to your application.
Setting properties programmatically requires writing the actual Java code that will accomplish the task. This approach offers more control, because elements not exposed by the Bean model may be accessed.
As mentioned previously, most properties in JClass Field have set
and get
methods associated with them. For example, to retrieve the value of the value
property in a JCTextField
instance, do the following:
TextFieldValueModel.getValue();
The following steps provide an outline for building a new Field component in an IDE.
Note that the changes to the JClass Field Component do not take effect until you click Apply and close the DataProperties editor.
![]() |
You might want to use existing JClass Field example code as a starting point for the new object. The examples and demos provided with JClass Field distribution are a good starting point. You can use the following steps as a general outline for creating a field component programmatically or start with the appropriate example field and modify to your specifications.
JC<DataType>Validator val = new JC<DataType>Validator();
JCInvalidInfo ii = NewField.getInvalidInfo();
Then set the InvalidInfo Properties using the table found in Section 2.4.5. NewField.setValueModel(new <DataType>ValueModel());
NewField.setValidator(val);
NewField.setInvalidInfo(ii);
You can use the ValueModel declaration to set the initial value for the field.
JCPromptHelper
and JCFormUtil
.Now that you have created your field, you can modify it to suit your specific needs. The following lists present the most common ways to customize a field. Use them as a guide to customizing your field. Example code for some of the methods here appears in chapter 4.
setMask()
.setNumMaskMatch()
.setPlaceHolderChars()
.setValidChars()
or setInvalidChars()
.setIncrement()
.editPattern()
and displayPattern()
.isCurrency()
.setRange()
.setFormat()
.editFormats()
.setPickList()
and setDisplayList()
.matchPickList()
.setDefaultValue()
.setCasePolicy()
.setInvalidPolicy()
.setInvalidForeground()
and setInvalidBackground()
. setBeepOnInvalid()
.JCPromptHelper
using setToolTipText()
.isEditable()
.JClass Field provides special components that connect and bind to IDE or JDBC-compliant data sources, including the database components that are part of Borland JBuilder 3.0 and WebGain (formerly Symantec) VisualCafé 3.0d or later.
Fields are bound to a particular column of a query result set and display the value at the current record. You can enable users to change the value, and have the field validate the change before committing the change back to the database. You can also change the current record displayed in the field programmatically or by using a GUI query navigation component.
There are five types of GUI components provided for data binding -- a text field, a spin field, a combo field, a popup field, and a label field. JClass Field's data-bound Beans dynamically determine their data type at runtime, based on the data type of the column they are bound to.
The Beans are packaged in a separate JAR file for each IDE environment; be sure you are using the correct one for your environment (see the Getting Started with JClass booklet for details). The following table lists the data-bound Field Beans included with this release:
Note: You must be using Borland JBuilder 3.0 or VisualCafé 3.0d or later to use the "JBdb" and "VCdb" IDE-specific Beans. Earlier versions will not work.
Before proceeding, you should ensure that your IDE and database are configured correctly and that you can create simple database applications.
JClass DataSource is a platform-independent JDBC-compliant hierarchical data source product. With it, your applications can bind to databases without being locked-into an IDE-specific data binding solution.
JClass DataSource is available separately or as part of the JClass Standard or Enterprise product bundle. Visit http://www.klgroup.com for more information and downloads.
Binding a field to a database in Borland JBuilder involves adding a database connection and query functionality using JBuilder Data Express components, and then using a JClass Field "JBdb" component to connect to the dataset column and display the data. This section walks through these steps.
Database setup, connection, and querying are handled by JBuilder components. Our coverage of these components is only intended as a guide. Consult your JBuilder documentation for detailed information on JBuilder database connectivity.
Use JBuilder's Database
Bean to create a database connection. This component is located on the
DataExpress
tab in the Component Palette.
Add an instance to your frame. Then, use the connection
property to specify the URL of the database you want to use.
To query the database, add an instance of JBuilder's QueryDataSet
(also on the
DataExpress
tab) to your frame.
Select the columns you want to retrieve with the query
property editor. For example, to select all of the columns from a table named OrderDetails, you would use a statement similar to:
select * from OrderDetails
![]() |
You can include all columns at this step, and then use a "JBdb" data-bound Bean to specify the column to display. Each column can be bound to a different "JBdb" field component.
With the database connection established and the query created, you can now add a data binding field Bean and connect it to the JBuilder DataSet to display the data. The data binding properties of the JBdbTextField
, JBdbSpinField
, JBdbComboField
, JBdbPopupField
, and JBdbLabelField
Beans are dataSet
and columnName
.
![]() |
Add a "JBdb" Bean to your frame.
Select a query from the dataSet
property's pull-down menu. If the database connection and query are set up correctly, there should be one or more queries in the list.
Then, select the column to display in the field using the columnName
property. Enter the column name into the property editor. The case must match that of the column name in the table.
The field displays the value at one particular record in the table; this is known as the current record. To display the value at another record, add a database navigation component such as the borland.jbcl.control.NavigatorControl
component, and connect it to the QueryDataSet
. You should then be able to traverse through the query, displaying each row in your data-bound fields.
With your connection established, you can then use the other Bean properties, such as DataProperties
, to configure the field's validation behavior. Note that because the data type of a field is determined by the column to which it is bound, you cannot access its type dependent properties in the DataProperties editor until it is bound to a specific column.
Binding a field to a database in VisualCafé involves connecting to and querying a database using VisualCafé data source components, and then using a JClass Field "VCdb" component to connect to, query, and display the data. This section walks through these steps.
Database setup, connection, and querying are handled by VisualCafé components. Our coverage of these components is only intended as a guide. Consult your VisualCafé documentation for detailed information on Café database connectivity.
An easy way to set up data binding in VisualCafé is to drag and drop a table from the
dbNavigator
window to the design area. This will set up the DatabaseManager
, JdbcConnection
, and QueryNavigator
all at once.
![]() |
When you see the QueryNavigator
icon in the design area, you can proceed to the next step -- connecting the chart to the database.
With the database connection and query created, you can now add a data binding field Bean and connect it to the Café QueryNavigator to display the data. The data binding property of the VCdbTextField
, VCdbSpinField
, VCdbComboField
, VCdbPopupField
, and VCdbLabelField
Beans is dataBinding
.
![]() |
Add a "VCdb" Bean to the design area.
You need to determine the alias name of the query navigator to bind the field to it. The easiest way to determine this is to copy it from the QueryNavigator
's property list.
Then, select the field Bean in the design area and click the dataBinding
property to display the property editor. Enter the query navigator alias you just determined into the
QueryNavigator Alias
field. Enter the name of the column to display in
Field Name
. Click
OK
to close the property editor.
![]() |
Test-run the application to see how the field displays the value from the database.
The field displays the value at one particular record in the table; this is known as the current record. You can use the QueryNavigator component to traverse through the query, displaying each row in your data-bound fields.
With your database connection working properly, you can then use the other Bean properties, such as validator
, to configure the field's validation behavior. Note that because the data type of a field is determined by the column to which it is bound, you cannot access its type dependent properties in the DataProperties editor until it is bound to a specific column.
The third way to add data binding to a JClass Field application is to use the data source components provided with JClass DataSource, a separately-available product from KL Group. JClass DataSource is a platform-independent JDBC-compliant hierarchical data source product.
Binding a field to a database with JClass DataSource involves adding a database connection and query using JClass DataSource's JCData
Bean and JCTreeData
Bean components, and then using a JClass Field "DSdb" component to connect to the JClass DataSource and display the data. This section walks through these steps using the JCData
Bean component.
Database setup, connection, and querying are handled by JClass DataSource. Our coverage of these components is only intended as a guide. Consult your JClass DataSource documentation for detailed information on configuring its components.
Add a JCData
Bean instance to your design area.
Then, use the dataBeanComponent
property editor to specify the URL of the database you want to use and the database query.
![]() |
The first thing to do is to set up a serialization file under the Serialization tab. This file saves information and settings about the connection. You can then proceed to set up a connection.
To set up a database connection, display the
Data Model
>
JDBC
>
Connection
tab and specify the Server Name and Driver for the database you want to connect to. Test the connection. When the connection is successful you can proceed to set up a query. The JClass DataSource documentation contains complete details on using the dataBeanComponent
property editor.
Display the Data Model > JDBC > SQL Statement tab to show the query options:
![]() |
You can create your entire query using mouse clicks (or you can enter it directly in the text window if you are proficient with SQL). First, add a table, and then create a query by selecting columns. When you have built the query, click Set/Modify and then Done .
You can include all columns at this step, and then use a "DSdb" data-bound Bean to specify the column to display. Each column can be bound to a different "DSdb" field component.
With the database connection established and the query created, you can now add a data binding field Bean and connect it to the JClass DataSource JCData
Bean to display the data. The data binding property of the DSdbTextField
, DSdbSpinField
, DSdbComboField
, DSdbPopupField
, and DSdbLabelField
Beans is dataBinding
.
![]() |
First, add a "DSdb" Bean to your design area.
Click the dataBinding
property to display its property editor. If the JCData
Bean's database connection and query are set up correctly, there should be one or more queries in the list.
![]() |
Double-click a query to display the available columns. Select the column to display in the field and click Done .
The field displays the value at one particular record in the table; this is known as the current record. You need to use a database navigation component to traverse to another record and display that value. JClass DataSource provides a Navigator
Bean that you can use for this purpose.
Add a DSdbNavigator
or DSdbJNavigator
to the design area and connect it to the JCData
Bean. You should then be able to traverse through the query, displaying each row in your data-bound fields.
With your connection established, you can then use the other Bean properties, such as validator
, to configure the field's validation behavior. Note that because the data type of a field is determined by the column to which it is bound, you cannot access its type dependent properties in the DataProperties editor until it is bound to a specific column.
JClass Field includes several sample programs that work with JClass DataSource, located in examples\field\db.
An application can use JClass Field to display and store abbreviated year values. For example, June 15, 1966 could be displayed as "15/06/66" in a date-type JCTextField
.
Using two-digits for year values introduces an ambiguity about which century or millenium the date applies to, especially near the beginning or end of a century. That is, "15/06/66" could be interpreted as either June 15, 1966 or June 15, 2066.
The best approach for avoiding Year 2000 problems in your application is to use four digits to specify year values. If this is not possible, JClass Field provides a milleniumThreshold
property that you can use to interpret two-digit years.
Located in the com.klg.jclass.field.validate.JCDateTimeValidator
class, milleniumThreshold
controls the interpretation of two-digit years. Any two-digit year less than the value of this property is considered to be after the year 2000, while any value greater than or equal to the threshold is considered to be after the year 1900.
The default threshold is 69. This means that a year value of "95" is treated as 1995 and a "01" value is treated as 2001. The following image shows the effect of using milleniumThreshold (the bottom field is invalid because 1900 is not a leap year).
![]() |
[Home] [Contents] [Index] [Javadoc] | Comments on the documentation? Please send them to jclass_docs@klgroup.com |
[Previous] [Next] | |
[Frames] [No Frames] |