Overblog Suivre ce blog
Administration Créer mon blog
9 décembre 2006 6 09 /12 /décembre /2006 11:56
Purpose

Here is a Java bean that allows to capture the mouse events and display the properties and methods of the clicked component.

Mouse events

Right-click on a component to display its properties and methods.


The Java code

     HandleMouseEvent.java



The implementation class of the Bean Item

     oracle.forms.fd.HandleMouseEvent


The methods you can call


  • Enable/disable mouse event capture

Set_Custom_Property('BLOCK.ITEM', 1, 'SETEVENT', 'parameter');


where parameter is:

   event name,boolean

e.g. :

Set_Custom_Property('BL.BEAN', 1, 'SETEVENT', 'PRESS=FALSE' ) ;         

event name can be one of the following:

  - MOVE (mouse move)
  - EXIT (mouse exit)
  - PRESS (mouse button pressed)
  - REL (mouse button released)
  - ENTER (mouse enter)
  - CLICK (mouse click)


   By default, the MOVE event is disabled.

  • Enable/disable all mouse events

Set_Custom_Property('BLOCK.ITEM', 1, 'ALLOWEVENT', 'true|false');


The event raised by the bean

  • SENDMSG

This event is raised by the bean to inform Forms that a mouse event has occured.
4 properties are provided:

  - MSGEVENT : event raised (mouse enter, exit, click, move, press)
  - MSGITEM : class name of the component
  - MSGCOORD : coordinates of the mouse pointer
  - MSGBTMOUSE : mouse button number

  IF (eventName='SENDMSG') THEN
      -- get the mouse message --
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MSGEVENT',eventValueType, LC$Event);
      get_parameter_attr(eventValues,'MSGITEM',eventValueType, LC$Item);
      get_parameter_attr(eventValues,'MSGCOORD',eventValueType, LC$Coord);
      get_parameter_attr(eventValues,'MSGBTMOUSE',eventValueType, LC$Button);
      LC$Msg := LC$Event
             || ' object=' || LC$Item
             || ' at ' || LC$Coord
             || ' mouse=' || LC$Button ;
      clear_message;
      Message(LC$Msg, no_acknowledge) ;
      Synchronize ; 


  • SENDPROPS

This event is raised by the bean to inform Forms that the property and method information of the component has been sent.
In the sample dialog, this information is stored in a Text item, then displayed via the Edit_TextItem() Forms built-in.
It can be displayed by right-clicking on anywhere on the screen.

Mouse events


   ELSIF (eventName='SENDPROPS') THEN
      -- get the component properties --      
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MSGPROPS',eventValueType, LC$Msg);
      :BL.PROPERTIES := Replace(LC$Msg, '/n', CHR(10));
      Set_Custom_Property('BL.BEAN', 1, 'ALLOWEVENT', 'false' ) ;
      Go_Item('BL.PROPERTIES');
      edit_textitem ;
      Set_Custom_Property('BL.BEAN', 1, 'ALLOWEVENT', 'true' ) ;
   END IF;



The sample dialog

     . Download the handlemouseevent.zip file
     . Unzip the file
     . copy the handlemouseevent.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file to add this jar file
     . Open the MOUSEEVENT.fmb module (Oracle Forms 10.1.2)
     . Compile all and run the module

Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
28 novembre 2006 2 28 /11 /novembre /2006 13:17

Purpose

Here is a Java bean that allows to send emails with html body and attachments.
It is a modified version of the Oracle Forms Demo's  javamail bean.


javamail

The javamail Oracle Forms Demo allows to send emails with attachments located on the server side.
This one is executed on the local machine, can send emails with html body and attachments from the local machine.

It needs the JavaMail(TM) API 1.4 release, so it can't run under JInitiator. You need to run the Sun Java Plug-in.



The Java code

     Sendmail.java     SendMessageException.java.java



The implementation class of the Bean Item

     oracle.forms.fd.SendMail


The methods you can call


  • Set the SMTP authentication

Set_Custom_Property('BLOCK.ITEM', 1, 'SET_MAIL_AUTHENTICATION', 'username,password');


If you provide authentication, this method must called first.


  • Set the mail parts 

Set_Custom_Property('BLOCK.ITEM', 1, 'SET_MAIL_INFOS', 'infos');


where infos are:

smtp addess | From | To | Subject | Body | attachment

e.g. :

 LC$Infos := :MAIL.SMTP_SERVER || '|'
           || :MAIL.FROM || '|'
           || :MAIL.TO || '|'
           || :MAIL.SUBJECT || '|'
           || :MAIL.BODY || '|'
           || :MAIL.ATTACHMENTS ;
          
  Set_Custom_Property( 'CONTROL.MAIL', 1, 'SET_MAIL_INFOS', LC$Infos ) ;
    

Each attached file in the list is separated with a coma.


Java security indication:

You have to update the .../Java/jre1.X.XX/lib/security/java.policy file to grant security permission

 permission java.security.AllPermission;


This bean need the mail.jar and activation.jar files wich are part of the JavaMail(TM) API 1.4 release
(these 2 jar files are provided with the zip file with this article)


The sample dialog

     . Download the javamail.zip file
     . Unzip the file
     . copy the mail.jar, activation.jar and SendMail.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file to add these 3 jar files
     . Open the javamail.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module

Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
6 novembre 2006 1 06 /11 /novembre /2006 10:42

Purpose

Here is a Java bean that allows to chat on a Forms application


Chat on Forms

It uses a modified version of the socketserver sample.
The list of chatters is held by a database table (CHAT) and a database package (PKG_CHAT) that get and dispatch the messages from/to the connected users.

REM Create the CHAT table
CREATE TABLE CHAT
(
  IP_ADDRESS VARCHAR2(15 BYTE),
  PORT       NUMBER(5,0),
  NAME       VARCHAR2(100 BYTE),
  FIRST_CONN DATE
)
/


The sample dialog provided with the bean allows to test the chat system.
When a chatter just connects, you can see his/her name in the chatter list.
Check the check-box if you want he/she receives your messages.
In the To send text box, use the Tab key to send the message.


The Java code

     ChatClient.java     ChatServer.java



The implementation class of the Bean Item

    oracle.forms.fd.ChatClient


The methods you can call


  • Init the socket server

Set_Custom_Property('BLOCK.ITEM', 1, 'INIT_SERVER', 'port_number');


e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'INIT_SERVER', '4450' ) ;
   


  • Stop the socket server


Set_Custom_Property('BLOCK.ITEM', 1, 'STOP_SERVER', '');

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'STOP_SERVER', '' ) ;
   



The event received from the Bean

  • SENDMSG

this event tells Forms that a message is sent by the Java Bean.
You can get it in a WHEN-CUSTOM-ITEM-EVENT event:

DECLARE
   
    eventName varchar2(30) := :system.custom_item_event;
    eventValues ParamList;
    eventValueType number;
    LC$Msg    varchar2(32000);
    LC$Value  varchar2(256);
   
BEGIN
   
   IF (eventName='SENDMSG') THEN
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MESSAGEVALUE',eventValueType, LC$Msg);
      -- Socket Server OK --
      If LC$Msg = '[SocketServerOK]' Then
        Set_Item_Property( 'BL.START', LABEL, 'Disconnect' ) ;
        :BL.STATUS := 'Connected on port ' || :BL.PORT  || CHR(10) || :BL.STATUS;
        Pkg_Chat.Open_Connexion( :BL.IP, :BL.PORT, :BL.NAME);
      -- new connexion --
      ElsIf Instr( LC$Msg, '[conn]' ) > 0 Then
        bell ;
        Query_Users ;
        :BL.STATUS := 'Connection of ' || Replace(LC$Msg,'[conn]','' )  || CHR(10) || :BL.STATUS;
      -- Deconnexion --
      ElsIf Instr( LC$Msg, '[deconn]' ) > 0 Then
        bell ;
        :BL.STATUS := 'Disconnection of ' || Replace(LC$Msg,'[deconn]','' )  || CHR(10) || :BL.STATUS;
        Query_Users ;
      -- Standard message --
      Else
         Add_Text( Replace(LC$Msg,'^',CHR(10)) ) ;
      End if ;
      Synchronize ;           
   END IF;
   
END;


The sample dialog

     . Download the chat.zip file
     . Unzip the file
     . run the chat.sql script on your database (the Oracle user must have access to the UTL_TCP package)
     . copy the chat.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the CHAT.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module

     the jar file must be signed.
     the jar file provided in this article is already signed.

Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
14 octobre 2006 6 14 /10 /octobre /2006 19:36

Purpose

Here is a Java bean that allows to transform a Forms module into a socket server.

This way, it can receive messages from the outside.
- In this example, the messages are sent through a telnet session.


Forms Socket Server

In this sample dialog, I have opened a telnet session:

   open localhost 4450

Then I can send messages to the Forms application.


- In another way, messages can also be sent by the database:

DECLARE
  c  utl_tcp.connection;  -- TCP/IP connection to the Socket server
  ret_val PLS_INTEGER;
BEGIN
  c := utl_tcp.open_connection(remote_host => '10.40.40.40',
                               remote_port =>  4450);  -- open connection
  ret_val := utl_tcp.write_line(c, 'Incoming Message Send by my Oracle DB');
  utl_tcp.close_connection(c);
END;



The Java code

     SocketServer.java     Server.java  



The implementation class of the Bean Item

     oracle.forms.fd.SocketServer


The methods you can call


Init the socket server

Set_Custom_Property('BLOCK.ITEM', 1, 'INIT_SERVER', 'port_number');

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'INIT_SERVER', '4450' ) ;
   
 

The event received from the Bean

SENDMSG


this event tells Forms that a message is sent by the Java Bean.
You can get it in a WHEN-CUSTOM-ITEM-EVENT event:

DECLARE
   
    eventName varchar2(30) := :system.custom_item_event;
    eventValues ParamList;
    eventValueType number;
    LC$Msg    varchar2(512);
    LC$Value  varchar2(256);
   
BEGIN
   
   IF (eventName='SENDMSG') THEN
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MESSAGEVALUE',eventValueType, LC$Msg);
      -- Display the message --
      :BL.MSGS := :BL.MSGS || LC$Msg || Chr(10) ;
      Synchronize ;           
   END IF;
   
END;


The sample dialog

     . Download the socketserver.zip file
     . Unzip the file
     . copy the socketserver.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the SOCKETSERVER.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module

     the jar file must be signed.
     the jar file provided in this article is already signed.
Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
13 octobre 2006 5 13 /10 /octobre /2006 15:10

Purpose

Here is a PJC that allows to set the cursor from any image stored in the jar file.

This PJC extends VTextField, so you must set the Implementation Class name on a Text item.


Text item and custom cursor


The Java code

     JTextFieldIcon.java  



The implementation class of the Bean Item

     oracle.forms.fd.JTextFieldIcon


The methods you can call


Set the image name

Set_Custom_Property('BLOCK.ITEM', 1, 'SETCURSOR', 'image_name');

e.g. :
Set_Custom_Property( 'BL.T1', 1, 'SETCURSOR', '/cursor1.gif' ) ;
   

   images are searched in the jar file.

The jar file provided with the article contains one icon : cursor1.gif


The sample dialog


     . Download the jtextfieldcursor.zip file
     . Unzip the file
     . copy the jtextfieldcursor.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the TEXTCURSOR.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module

Repost 0
Published by Oracle Forms community - dans PJC - Text items
commenter cet article
11 octobre 2006 3 11 /10 /octobre /2006 21:27

Purpose

Here is a Java Bean that allows to use regular expressions with the Sun Java Plug-in.

Regular expressions have been introduced in the Oracle database with the version 10g.
For those who still use a previous version, this Java Bean allows to use regular expressions to achieve complex validations in the Forms text items.
Because the java.util.regex package is available since the 1.4 version of the JDK, we cannot use it with JInitiator that use the 1.3 instruction set. This is the reason why this Bean works only with the Sun Java Plug-in.


regular expression with the Java Plugin


The Java code

     RegularExp.java  



The implementation class of the Bean Item

     oracle.forms.fd.RegularExp


The methods you can call

Set the pattern

Set_Custom_Property('BLOCK.ITEM', 1, 'SET_PATTERN', 'pattern');

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, '
SET_PATTERN', '
[A-Z][a-z][a-z][a-z]' );   


Set the string to check


Set_Custom_Property('BLOCK.ITEM', 1, 'SET_STRING', 'string');




The properties you can get from the JavaBean


Get the boolean result

Varchar2 :=
Get_Custom_Property( 'BL.BEAN', 1, 'GET_RESULT' ) ;

returns either true or false


Get the corresponding group sub-string

Varchar2 :=
Get_Custom_Property( 'BL.BEAN', 1, 'GET_GROUP' ) ;



Get the start and end position of the substring

Varchar2 :=
Get_Custom_Property( 'BL.BEAN', 1, 'GET_POS' ) ;

returns a value like : start_position,end_position




The sample dialog


     . Download the regularexp.zip file
     . Unzip the file
     . copy the regularexp.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the REGULAREXP.fmb module (Oracle Forms 10.1.2 and Java Plug-in 1.5.0_06)
     . Compile all and run the module

Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
1 octobre 2006 7 01 /10 /octobre /2006 11:15

Purpose

Here is a Java Bean that allows to read, display and write images.

(See the last evolution of this solution here


When you load an image within Forms with the Read_Image_File() built-in, you can notice a certain lack of quality, both in the Forms Image item display quality and in the real information stored in the blob column.
The image seems to be compressed before it is stored in the database. This compression rate is between 25 and 50% !
This Java Bean allows to load images from a file, then store them in the database.

The Forms sample dialog provided with the article uses two image rooms:

 - The first one is a standard Forms Image item that is populated with the Client_Image.Read_Image_File() Webutil function that populates the PHOTO blob column.


 - The second one is the Java Bean itself that populates the PHOTO_JAVA blob column.


As you see as follows, the Read_Image_File() function can drastically compress the initial image:

1 select
2 identifiant,
3 length(photo),
4 length(photo_java),
5 round((length(photo)/length(photo_java)*100),1) || '%' "photo reduction"
6 from photos
7* where photo is not null
SQL> /

IDENTIFIANT LENGTH(PHOTO) LENGTH(PHOTO_JAVA) photo reduction
----------- ------------- ------------------ ---------------
2           23536         100952             23.3%
1            6763          13548             49.9%
 

This JavaBean connect to the database through the JDBC driver to read and write the images.
Of course, some of you can complain that this solution needs a second connection, the loading of the classes12.jar file on the client machine, so it is "deconnected" from the Forms transaction.
For this very moment, my answer is : everything has its price, and if you need to keep and display the real quality of the images in your Forms application, this bean is the one you need.

Let's see the screenshot to decide !

handleimage small format

Click here to get the full format image


The Java code

     HandleImage.java     LectureBlob.java    myPanel.java



The implementation class of the Bean Item

     oracle.forms.fd.HandleImage


The methods you can call

Set the connection string

Set_Custom_Property('BLOCK.ITEM',1,'SETCONN','the_connection_string');

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, '
SETCONN', 'jdbc:oracle:thin:@my-machine:1521:XE' ) ;   
(Provide the complete jdbc:oracle:thin:... syntax)


Set the username


Set_Custom_Property('BLOCK.ITEM',1,'SETUSER','username');


Set the password

Set_Custom_Property('BLOCK.ITEM',1,'SETPWD','password');


Set the
database image table information

Set_Custom_Property('BLOCK.ITEM',1,'SETTABLEINFO','p1,p2,p3');

p1 is the table name that hold the image blob column
p2 is the column name that hold the image
p3 is the column name that identifies the unique row in the table (for the UPDATE statment)

e.g.:
Set_Custom_Property( 'BLZ.BEAN', 1, 'SETTABLEINFO', 'PHOTOS,PHOTO_JAVA,IDENTIFIANT' ) ;  

The instruction above indicates that the PHOTOS table handle images in the PHOTO_JAVA blob column, and the key column that identifies the unique row is IDENTIFIANT.


Read an image from a local file

Set_Custom_Property('BLOCK.ITEM',1,'READIMGFILE','the_complete_filename');

e.g.:
Set_Custom_Property( 'BLZ.BEAN', 1, 'READIMGFILE', 'D:/image.jpg' ) ; 


Read an image from the database table

Set_Custom_Property('BLOCK.ITEM',1,'READIMGBASE,'unique_ID');

e.g.:
Set_Custom_Property( 'BLZ.BEAN', 1, 'READIMGBASE', '1' ) ; 

unique_ID is the value to identify a unique row to update in the table. The above instruction will be interpreted as :

   Select PHOTO_JAVA From PHOTOS Where IDENTIFIANT = 1


Put this method into the When-New-Record-Instance block-level trigger


Write an image to the database table

Set_Custom_Property('BLOCK.ITEM',1,'WRITEIMGFILE','unique_ID');

e.g.:
Set_Custom_Property( 'BLZ.BEAN', 1, 'WRITEIMGBASE', '1' ) ; 

unique_ID is the value to identify a unique row to update in the table.
The above instruction will be interpreted as :

   Update PHOTOS Set PHOTO_JAVA = ? Where IDENTIFIANT = 1


Put this method into the Post-Insert and Post-Update block-level triggers



Clear the image

Set_Custom_Property( 'BL.BEAN', 1, '
CLEAR' , '' ) ;

This function has to be called in a When-New-Record-Instance trigger if the record does not exist:

When-New-Record-Instance trigger:
If :PHOTOS.IDENTIFIANT is not null Then
   Set_Custom_Property( 'BLZ.BEAN', 1, 'READIMGBASE', :PHOTOS.IDENTIFIANT ) ;
Else
   Set_Custom_Property( 'BLZ.BEAN', 1, 'CLEAR', '' ) ;
End if ;
:BLZ.IMG_SIZE := Get_Custom_Property( 'BLZ.BEAN', 1, 'GETSIZE' ) ;


Set the log mode to output the Bean messages

Set_Custom_Property( 'BL
.BEAN', 1, 'SETLOG' , 'true|false' ) ;



Set mode to allow the display of the scrollbars if needed

Set_Custom_Property( 'BL.BEAN', 1, 'SET
SCROLL' , 'true|false' ) ;


In the sample dialog, here is the code used in the When-New-Form-Instance trigger:

PROCEDURE InitForm IS
BEGIN
  -- switch the log to true --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETLOG', 'true' ) ;
  -- set the baen image bckground color --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETBG', '255,255,255' ) ;
  -- set the JDBC connection information --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETCONN', 'jdbc:oracle:thin:@my-machine:1521:XE' ) ;
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETUSER', 'tutoforms' ) ;
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETPWD',  'tuto' ) ;
  -- set the image table and column name --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETTABLEINFO',  'PHOTOS,PHOTO_JAVA,IDENTIFIANT' ) ;
  -- allow the bean to display scrollbars --
  Set_Custom_Property( 'BLZ.BEAN', 1, 'SETSCROLL',  'true' ) ; 
END;

Here is the description of the database table used:

CREATE TABLE PHOTOS
   (   
      "IDENTIFIANT" NUMBER(5,0) NOT NULL ENABLE,
      "NOM" VARCHAR2(50 BYTE),
      "PHOTO" BLOB,
      "PHOTO_JAVA" BLOB,
      CONSTRAINT "PHOTO_PK" PRIMARY KEY ("IDENTIFIANT") ENABLE
   )
/



The properties you can get from the JavaBean


Get the image size

Varchar2 :=
Get_Custom_Property( 'BL.BEAN', 1, 'GETSIZE' ) ;

The format returned (width,height) is like the following : 50,120


Accessing to a remote database

Because the JavaBean is executed within an applet, it is not possible to connect to a remote database without a little adaptation:

   - first, the jar file must be signed.
   - second : you have to update the java.policy file stored in the Jinitiator directory

For example, to access to the database located on the machine-name server on the port 1524, add the following lines to the java.policy file:

C:/Program Files/Oracle/JInitiator 1.3.1.xx/lib/security/java.policy file

 

 permission java.net.SocketPermission "machine-name:1524-", "accept,connect,listen,resolve"; 
permission java.security.AllPermission;



The sample dialog



     . Download the handleimage.zip file
     . Unzip the file
     . run the create_table.sql under the Oracle user you want to test (It creates the sample image table).
     . copy the handleimages.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file to add both handleimages.jar and classes12.jar (the classes12.jar is located in the <DEV_HOME>/jdbc/lib directory. add a copy of this file in the <DEV_HOME>/forms/java directory).
     . Open the HANDLEIMAGE.fmb module (Oracle Forms 10.1.2)
     . Compile all and run the module

     . Enter a valid file name in the Image File name item then press the Read image file button


Note : If you rebuild the jar file, it has to be signed. (the handleimages.jar file provided in this article is already signed).
Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
28 août 2006 1 28 /08 /août /2006 22:19

Purpose

Here is a Java Bean that allows to start asynchronous jobs from an Oracle Forms application.

When you execute a stored procedure or function within a Forms application, the end user cannot get the hand until the procedure/function is completly finished, so the application seems to be "frozen".
By using a class that implements the Runnable interface, it is possible to run a job in its own thread, so the end user can continue to work while the execution of the stored function.

The JavaBean can connect to the database through the JDBC driver, execute the stored procedure/function, then call back Forms to indicate the end of the job.


The Java code

     asyncjob.java


The implementation class of the Bean Item

     oracle.forms.fd.AsyncJob


The methods you can call

Set the connection string

Set_Custom_Property('BLOCK.ITEM',1,'INITCONN','the_connection_string');


e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'INITCONN', 'jdbc:oracle:thin:@my-machine:1521:XE' ) ;   
(Provide the complete jdbc:oracle:thin:... syntax)


Set the username


Set_Custom_Property('BLOCK.ITEM',1,'INITUSER','user_name');


Set the password


Set_Custom_Property('BLOCK.ITEM',1,'INITPWD','password');


Set the call of a function


Set_Custom_Property('BLOCK.ITEM',1,'INITFUNC','the_function_call');

e.g.:
Set_Custom_Property( 'BL.BEAN', 1, 'INITFUNC', 'begin ? := F1(5); end;' ) ; 


Set the call of a procedure


Set_Custom_Property('BLOCK.ITEM',1,'INITPROC','the_procedure_call');

e.g.:
Set_Custom_Property( 'BL.BEAN', 1, 'INITPROC', 'begin P1(5); end;' ) ; 



Set the log mode to output the Bean messages

Set_Custom_Property( 'BL.BEAN', 1, 'SETLOG' , 'true|false' ) ;


In the sample dialog provided with the article, I use 2 buttons:

- One to execute a stored function:

  If :BL.CONN_STRING is not Null
      And :BL.USERNAME is not Null
      And :BL.PASSWORD is not Null Then
    Set_Custom_Property( 'BL.BEAN', 1, 'SETLOG' , 'true' ) ;
    Set_Custom_Property( 'BL.BEAN', 1, 'INITCONN', :BL.CONN_STRING ) ;   
    Set_Custom_Property( 'BL.BEAN', 1, 'INITUSER', :BL.USERNAME ) ;
    Set_Custom_Property( 'BL.BEAN', 1, 'INITPWD' , :BL.PASSWORD ) ;   
    Set_Custom_Property( 'BL.BEAN', 1, 'INITFUNC', 'begin ? := ' || :BL.SQL_ORDER || ' end;' ) ; 
    Message('Command sent'); synchronize;
  End if ;
   

- Another to execute a stored procedure:

  If :BL.CONN_STRING is not Null
      And :BL.USERNAME is not Null
      And :BL.PASSWORD is not Null Then
    Set_Custom_Property( 'BL.BEAN', 1, 'SETLOG' , 'true' ) ;
    Set_Custom_Property( 'BL.BEAN', 1, 'INITCONN', :BL.CONN_STRING ) ;
    Set_Custom_Property( 'BL.BEAN', 1, 'INITUSER', :BL.USERNAME ) ;
    Set_Custom_Property( 'BL.BEAN', 1, 'INITPWD' , :BL.PASSWORD ) ;   
    Set_Custom_Property( 'BL.BEAN', 1, 'INITPROC', 'begin ' || :BL.SQL_ORDER || ' end;' ) ;
    Message('Command sent'); synchronize;
  End if ;
   

The event that can be raised from the JavaBean

   EVENT

It indicates to Forms that the procedure/function is finished.
You can catch this event in the WHEN-CUSTOM-ITEM-EVENT trigger of the Bean item:

Declare
    LC$Error   Varchar2(4000) ;
    LC$Result  Varchar2(32000) ;
Begin   
  clear_message ;
  LC$Error  := Get_Custom_Property('BL.BEAN',1, 'GETERROR') ;
  LC$Result := Get_Custom_Property('BL.BEAN',1, 'GETRESULT') ;
  If LC$Error is not null Then
       Message( 'Error : ' || LC$Error ) ;
  Else
     Message( LC$Result, no_acknowledge);
  End if ;
End ; 

As you can see, the 2 properties you can get from the JavaBean are the return value (GETRESULT) and the error message (GETERROR) provided by the execution.

For this case I have created one stored function and one stored procedure like the following:

CREATE OR REPLACE
PROCEDURE P1 ( PN$Param IN NUMBER )
IS
BEGIN
  DBMS_LOCK.Sleep( PN$Param ) ;
END;
/

CREATE OR REPLACE
FUNCTION F1 ( PN$Param IN NUMBER )
RETURN VARCHAR2
IS
BEGIN
  DBMS_LOCK.Sleep( PN$Param ) ;
  RETURN ('Function ended at ' || To_Char(SYSDATE,'HH24:MI:SS') );
END;
/

As you can see, they do nothing else than waiste some time.
You can get the creation source in the asyncjob.sql provided with the sample.

To compile this code, the user must have the execute privilege on the SYS.DBMS_LOCK package granted.


Accessing to a remote database

Because the JavaBean is executed within an applet, it is not possible to connect to a remote database without a little adaptation:

   - first, the jar file must be signed.
   - second : you have to update the java.policy file stored in the Jinitiator directory

For example, to access to the database located on the machine-name server on the port 1524, add the following lines to the java.policy file:

C:/Program Files/Oracle/JInitiator 1.3.1.xx/lib/security/java.policy file

 permission java.net.SocketPermission "machine-name:1524-", "accept,connect,listen,resolve"; 
permission java.security.AllPermission;



The sample dialog

asynchronous job


     . Download the asyncjob.zip file
     . Unzip the file
     . run the asyncjob.sql under the Oracle user you want to test (It creates the 2 small stored function/procedure).
     . copy the asyncjob.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file to add both asyncjob.jar and classes12.jar (the classes12.jar is located in the <DEV_HOME>/jdbc/lib directory. add a copy of this file in the <DEV_HOME>/forms/java directory).
     . Open the ASYNCJOB.fmb module (Oracle Forms 10.1.2)
     . Compile all and run the module



Note : If you rebuild the jar file, it has to be signed. (the asyncjob.jar file provided in this article is already signed).
Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
8 juillet 2006 6 08 /07 /juillet /2006 16:27

Purpose

Here is a Java Bean that allows to write/read files on the client machine without installing Webutil.

The Java code

     clientfile.java


Register the Bean

The bean must be registered before you can call its methods.
Because the Bean cannot be registered at the very start of the form (When-New-Form-Instance for example), we need to place this instruction in a When-Timer-Expired trigger:

When-New-Form-Instance trigger:

DECLARE
    timer_id Timer;
BEGIN
    timer_id := CREATE_TIMER('bean_timer', 200, NO_REPEAT);
END;



When-Timer-Expired trigger:

FBean.Register_Bean('BL.BEAN_ITEM',1,'oracle.forms.fd.ClientFile');


In my sample dialog, I have a bean area called BEAN_ITEM in the BL block.

The bean is registred, now, so we can invoke its methods:


The methods you can call

Set the filename

FBean.Invoke('BLOCK.ITEM',1,'setFileName','the_file_name');


Write the text to this file

FBean.Invoke('BLOCK.ITEM',1,'writeToFile','the_text');


Append the text to this file

FBean.Invoke('BLOCK.ITEM',1,'writeAppendToFile','the_text');


Read the text from this file

varchar2 := FBean.Invoke_Char('BLOCK.BEAN',1,'readFromFile','');


Set the log mode to output the Bean messages

FBean.Invoke('BLOCK.ITEM',1,'SetLog','');


In the sample dialog provided with the article, I use 2 buttons:

- One to write the text:

If :BL.filename is not null Then
   -- set the log on --
   FBean.Invoke('BL.BEAN_ITEM',1,'SetLog','');
   -- set the file name --
   FBean.Invoke('BL.BEAN_ITEM',1,'setFileName',:BL.filename);
   -- write the text --
   FBean.Invoke('BL.BEAN_ITEM',1,'writeToFile','"' || :BL.write || '"');
End if ;   

- Another to read the text:

If :BL.filename is not null Then
   -- set the log on --
   FBean.Invoke('BL.BEAN_ITEM',1,'SetLog','');
   -- set the file name --
   FBean.Invoke('BL.BEAN_ITEM',1,'setFileName',:BL.filename);
   -- read the text from the file --
   :BL.READ := FBean.Invoke_Char('BL.BEAN_ITEM',1,'readFromFile','');
End if ;   


The sample dialog

clientfile


     . Download the clientfile.zip file
     . Unzip the file
     . copy the clientfile.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the CLIENTFILE.fmb module (Oracle Forms 10.1.2)
     . Compile all and run the module



Note : If you rebuild the jar file, it has to be signed. (the clientfile.jar file provided in this article is already signed).
Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article
14 avril 2006 5 14 /04 /avril /2006 16:55

Purpose

This is the part II of the utilities Java Bean.

utilities (2)

A second tab allows to manipulate some Text field properties.

  . You can set dynamically the maximum of  charaters the user can enter.
  . You can also set the cursor blink rate and the cursor style.


The Java code

      FJTextField.java


The Implementation Class property

      forms.fd.utilities.FJTextField


The properties you can set

The maximum characters the user can enter

Set_Custom_Property( 'BL.BEAN', 1, 'SETMAX', 'max_length' ) ;

The cursor blink rate

Set_Custom_Property( 'BL.BEAN', 1, 'SETBLINKRATE', 'value' ) ;

100 is very fast and 800 is very slow

The cursor style

Set_Custom_Property( 'BL.BEAN', 1, 'SETCURSOR', 'style' ) ;

Where style can be one of the following:

   . DEFAULT
   . HAND
   . CROSS
   . MOVE
   . TEXT
   . WAIT


The sample dialog

     . Download the utilities.zip file
     . Unzip the file
     . copy the fjutilities.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the UTILITIES.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module


Repost 0
Published by Oracle Forms community - dans Bean - general
commenter cet article