Application Techniques

Using JavaBeans on Forms

How to include and use a JavaBean component on a form.

About this technique



Core Programming Techniques> General


You'll learn about:

You can run this technique code from:

NOTE   First make sure that database is running on your localhost SilverStream Server

Related reading

See the chapter on using utility classes, JAR files, and JavaBeans in the Programmer's Guide

This example also includes information on where to store the bean's jar file and how to use its methods to perform tasks.

Adding a JavaBean to a form   Top of page

The following describes how to add a JavaBean to a form:

  1. Ensure that the bean is in the Examples3_Java database, in Media/Jars. In this example, the bean is stored as the AgCalendar.jar file.

  2. In the Form Designer, click Examples3_Java/Media/JavaBeans/AgCalendar.

Modifying the properties of a JavaBean   Top of page

As with other controls in SilverStream forms, you can modify the properties of a JavaBean by right-clicking it and selecting Properties to use the Properties dialog box.

In this bean example, one of the bean's properties you can modify is the selected background color. In setting this property, you are setting the background color of the user-selected date so that each time the user clicks a date in the calendar, the clicked date's color changes from the default background color to this color. Set this property as follows:

  1. Right-click the bean (named AgCalendar) and select Properties.

  2. In the Properties dialog, select the Control tab.

  3. In the Selected Background field, choose the desired color.

Displaying the selected date in a text field   Top of page

The following code shows how to get the user-selected date of a calendar JavaBean and display it in a text field.

  private void handle_btnGetCurrent_actionPerformed(ActionEvent evt) 
     GregorianCalendar current; 
     // Get the current date. 
     current = AgCalendar.getCurrentDate(); 
     // Set the field on the form with the current date. 
     // Need to subtract 1900 from the GregorianDate because 
     // the field on the form is a java.sql.Data which is 1900  
     // based. 
     fldCurrentDate.setValue( new 
       java.sql.Date(current.get(Calendar.YEAR) - 1900,  
        current.get(Calendar.MONTH), current.get(Calendar.DATE))); 

Notes about the code

Copyright © 2000, SilverStream Software, Inc. All rights reserved.