Forms: How to use a calendar in a Form

, , No Comments
Collcted from the link: https://sites.google.com/site/craigsoraclestuff/oracle-forms---how-to-s/forms-how-to-use-a-calendar-in-a-form

Introduction

How to implement a Calendar object in an Oracle Form is a fairly common question in the Oracle Technology Network Forms Forum. There are a couple of very nice demo’s available on the Internet as well as Oracle’s own demo in the Forms Code Samples. However, because it is getting harder and harder to find the demo’s on Oracle’s site, I decided to write this document.

Disclaimer

I want to be very clear – I did not write either of these calendars. I am simply writing this document as a way of making information that is available in separate documents available in a single document. Please check the references section for information on where I obtained the source code for these calendars.
 
Between the two solutions (Forms versus Java) I prefer the Forms version solely because it is a little faster (based solely on my experience) than the Java version and the Java version does not conform to the look and feel of a Forms application.

How this document is organized

This document will take you step-by-step through implementing both a Forms based calendar (adapted from Oracle’s supplied demo’s) as well as a Java based calendar (see Resources at the end of this document).
I will list the steps to use the Forms calendar first and then list the step to use the Java version second. This demo is organized such that there are two separate Date items in the Form; the first using the Forms Calendar and the second using the Java calendar. This allows you to judge for yourself which one is more suitable for your needs.
This document will walk you step-by-step through the creation of an Oracle Form that implements both calendars – even though I have included all the source code.

Forms Version

This demo was written using Oracle Developers Suite 10g R1 (10.1.2.0.2) with no patches applied. This makes it usable by any version of Forms 10g.

Objects included in this demo

  • CALENDAR.olb
  • FJCalendar.jar
  • jcalendar-1.3.2.jar
  • looks-2.0.1.jar
  • FRM_JAVA_CALENDAR.fmb
  • How to implement a Calendar object in an Oracle Form.doc
(See the Calendar.zip file in the attachments section below)

Java Requirements!

The Java Runtime Environment (JRE) needed to run this demo is the Sun JRE version 1.5.0_22, but it is highly recommended that you use the latest Sun JRE (currently 1.6.0_22). If you want to configure Forms Builder to use the Sun JRE, but don’t know how too, see my article: "Forms How to – Configure Forms Builder to use Sun JRE.”
 
If you need a version of the Java calendar that runs with the Oracle Jinitiator please the references section for the URL where I got the Java calendar. 

Setup

  1. Copy the supplied CALENDAR.olb to a directory listed in your FORMS_PATH.
  2. The .jar files listed above must be copied to the <DEV_SUITE_HOME>\forms\server\java folder and you must modify the default.env CLASSPATH to include the full path to the FJCalendar.jar.
    (For example: C:\DevSuiteHome10g\forms\java\FJCalendar.jar)
  3. The .jar file must be listed in the ARCHIVE parameter in the formsweb.cfg.
    (For example:  archive=frmall.jar,FJCalendar.jar

Let’s get started!

First, you will need to have the Oracle Developer Suite 10g R2 (10.1.2.0.2) installed and configured to run forms locally. If you are unable to run a form from the Forms Builder – then you will need an application server available where you can deploy and test your form. I prefer running a Form from the Forms Builder as it allows me to incrementally develop a form as well as run the Forms Debugger if I run into trouble with a particular section of code. This document assumes you have completed the necessary configuration to run a form from the Forms Builder. If you need assistance configuring Forms Builder to run forms locally, see my article: “"Forms: How to Configure Forms Builder to run forms locally.
 

Step-by-Step

  • Start the Forms Builder and create a new Forms Module.
  • Log into a database – doesn’t matter which database because the form we’re creating does not have any base table objects.
  • Open the CALENDAR.olb and double-click on the CALENDAR node in the Object Libraries.
  • This will open the CALENDAR object library pane.
  • From the CALENDAR object library pane, click on CALENDAR and drag and drop it on the Object Groups node of your new form.
  • You will be prompted to Subclass, Copy or cancel the operation. It is recommended that you subclass the objects, but you can copy them if you prefer.
    1. If you subclass – the CALENDAR.olb must be located in a directory listed in your FORMS_PATH (as mentioned above).
    2. Once copied or subclassed, you should see the following objects in the Forms Object Navigator (note; my example has the little red arrow on each object indicating that this object is subclassed).
    3. Now lets add the rest of the objects needed for this demo. I use a control block in this demo so there is no need to create any tables to support this demo.
  • Go to the Windows node of the object navigator and open the property pallet of the WINDOW1 object and set the following properties: (WINDOW1 is created by default by the Forms Builder)
    1. Name: MAIN
    2. Width: 380
    3. Height: 225
  • Now, select the Module node (very top) and set the following properties:
    1. Name: FRM_JAVA_CALENDAR
    2. Title: Forms and Java Calendar Demo
    3. Console Window: MAIN
  • Add a new Canvas object to the Canvases node and then open the property pallet for the canvas and set the following properties:
    1. Name: CALENDAR
    2. Window: MAIN
    3. Width: 380
    4. Height: 225
  • Create a new Data Block and select “Build a new block manually”.
    1. Ensure this block appears first in the list before the DATE_CONTROL_BLOCK and DATE_BUTTON_BLOCK blocks.
    2. Open the property pallet for the new block and set the following properties:
      1. Name: CONTROL
      2. Database Data Block: No
  • Click on the Items node of the CONTROL block and Add 5 new items.
    1. Click on the first item and set the following properties:
      1. Name: FORMS_DATE
      2. Data Type: DATE
      3. Canvas: CALENDAR
      4. X Position: 90
      5. Y Position: 45
      6. Prompt: Forms Dat
    2. Select the second item and set the following properties:
      1. Name: JAVA_DATE
      2. Data Type: DATE
      3. Canvas: CALENDAR
      4. X Position: 90
      5. Y Position: 60
      6. Prompt: Java Date
    3. Select the third item and set the following properties:
      1. Name: BTN_FORMS_DATE
      2. Item Type: Push Button
      3. Label: Forms Date
      4. Canvas: CALENDAR
      5. X Position: 160
      6. Y Position: 45
    4. Select the fourth item and set the following properties:
      1. Name: BTN_JAVA_DATE
      2. Item Type: Push Button
      3. Label: Java Date
      4. Canvas: CALENDAR
      5. X Position: 160
      6. Y Position: 60
    5. Select the fifth item and set the following properties:
      1. Name: BEAN_AREA
      2. Item Type: Bean Area
      3. Implementation Class: oracle.forms.fd.JCalendar
      4. Canvas: CALENDAR
      5. X Position: 20
      6. Y Position: 30
      7. Width: 0
      8. Height:
        Note: It is important that your Bean Area be zero size and visible or the Java Calendar will not display properly.
        At this point, your Form should look like the following:

        Now we are ready to start writing the code to display and capture the dates from the calendars.
  • First, we need to compile all code in the Form. I prefer keyboard short-cuts, but you can use the menu if you prefer.
    1. Program Menu => Compile PL/SQL => All
      OR
    2. Ctrl + Shift + K
  • Select BTN_FORMS_DATE item and add a When-Button-Pressed trigger with the following code:

     
    DECLARE
      cur_x_pos    INTEGER := 0;
      cur_y_pos    INTEGER := 0;
      new_x_pos   INTEGER := 0;
      new_y_pos   INTEGER := 0;
      item_height   INTEGER := 0;
      my_date       VARCHAR2(25);
    BEGIN
      cur_x_pos := Get_Item_Property('CONTROL.FORMS_DATE',x_pos);
      cur_y_pos := Get_Item_Property('CONTROL.FORMS_DATE',y_pos);
      item_height := Get_Item_Property('CONTROL.FORMS_DATE',height);

      new_x_pos := cur_x_pos;
      new_y_pos := cur_y_pos + item_height + 2;
     
      Date_Lov.get_Date(display_date => sysdate
                                                                ,return_item => 'CONTROL.FORMS_DATE'
                                                                ,v_x_pos => new_x_pos
                                                                ,v_y_pos => new_y_pos
                                                                ,v_title => 'FORMS DATE PICKER'
                                                                ,v_ok => 'OK'
                                                                ,v_cancel => 'Cancel'
                                                                ,V_highlight => FALSE
                                                                ,v_autoconfirm => FALSE
                                                                ,v_autoskip => FALSE
      );
    END;
  • Select the BTN_JAVA_DATE item and add a When-Button-Pressed trigger with the following code:
     BEGIN
      Set_Custom_Property('CONTROL.BEAN_AREA',1,'SHOW_CALENDAR','50,50');
    END;
  • Lastly, we need to add a When-Custom-Item-Event trigger to CONTROL.BEAN_AREA with the following code:
     
    DECLARE
      event_name               VARCHAR2(30) := :system.custom_item_event;
      event_vals                 ParamList;
      event_val_type          NUMBER;
      jb_date                      VARCHAR2(256);    --Complete Date
      jb_day                       VARCHAR2(256);    --Day Number (1-31)
      jb_month                   VARCHAR2(256);    --Month Number (1-12)
      jb_year                      VARCHAR2(256);    --Year number (YYYY)
    BEGIN
      IF ( event_name = 'CALENDAR_EVENT' ) THEN
        event_vals := Get_Parameter_List(:SYSTEM.Custom_Item_Event_Parameters);
        Get_Parameter_Attr(event_vals, 'CALENDAR_EVENT_DATE', event_val_type, jb_date);
        Get_Parameter_Attr(event_vals, 'CALENDAR_EVENT_DAY', event_val_type, jb_day);
        Get_Parameter_Attr(event_vals, 'CALENDAR_EVENT_MONTH', event_val_type, jb_month);
        Get_Parameter_Attr(event_vals, 'CALENDAR_EVENT_YEAR', event_val_type, jb_year);
        :CONTROL.JAVA_DATE := jb_month||'/'||jb_day||'/'||jb_year;
        Synchronize;
        END IF;    
    END;
We’re now ready to test the form. If you have configured Forms Builder to run forms locally, make sure you start the OC4J Instance first, and then Click on the Run Icon () in the toolbar or press Ctrl + R.

Your form should look like the following:
Forms Date Picker:


Java Date Picker:

Final Results:


 

Reference:


Download the example from : Calender example

0 comments:

Post a Comment