Sunday, 13 July 2008

Creating and using Java beans in Oracle Forms builder

Probably anyone who uses Oracle Forms Builder, at some point found himself with a certain problem that is very hard to fix using Oracle Forms Builder only, although it gives prety much everything you need to build a database application.

On the other hand , large number of those who managed to solve the problem weren’t even aware of a fact that they were able to solve that ’large’ and unusual problem by using Java beans, which can be used in Oracle Forms Builder.

Not to mention that many developers don’t even know about this functionality of Forms Builder that enables us to use Java code in our Oracle Forms application, and those who do know about it don’t know HOW to do it!

What I now plan to do is to show you how you can create and use some simple java bean in your Oracle Forms application.

These examples are far from usefull and complex but it will help you understand how to make a java bean and then you can create very usefull and complexe modules using almost complete power of Java...

I use Oracle 10g , and Developer suite 10g , and that means that we must use 1.4 version of java while building our bean.

Let’s open Eclipse and create new Java Project. Let’s call it „MyBean“ , and let’s create one Java class called „FirstBean“. For now, we have something like this:

The easiest way of creating a java bean that we can use in oracle forms builder, is to extend Vbean class. Vbean is located in frmall.jar. You can find it in %ORACLE_HOME%\forms\java on windows. ( for example, I have it on location C:\oracle\DevSuite\forms\java )

In order to use it, open project -> properties in eclipse , and under „java build path“ click on the Libraries tab , and then select frmall.jar by clicking on the „Add external jars“ button.

I mentioned before that we must use 1.4 compiler compliance level , so select it from drop down list, under „Java compiler“.

Click apply .

I will make a bean that we can use to:

- Get our own IP address

- Switch letters case of some string to upper case

- and to show input dialog for a user to enter some string and retrieve that string.

These examples are more than trivial , but they will help you understand a logic of building java beans that you can use in oracle forms builder.

You will soon see that we communicate with java beans by setting and getting some custom properties. all this is done by the use of the getPropery and setPropety methods defined in the Iview interface. Each property is created and stored within the oracle.forms.properties.ID class.

Let’s make 5 of it:

We will use I_TEXT to set an input dialog text, IP to retrieve ip address , SET_STRING to set a string for which we change letters case , SHOW_INPUT to say a java bean that we want to show input dialog, and UPPER_CASE to say a java bean that we want to retrieve (upper cased) string that we sent earlier.

So, the only two things we need to set before getting the result from java bean are I_TEXT ( text to be shown on input dialog) and SET_STRING ( the string that is about to be upper cased ).

In order to set it, we must use setter setProperty() :

and later when we call SET_CUSTOM_PROPERTY in PL/SQL we will send it’s value.

example:

If we have a BEAN_AREA in oracle forms called BLOCK4.BEAN_AREA11 , and want to set I_TEXT ( input dialog text ) to be : „Please insert a value:“ , we would call

I really can tell just by looking these errors...It looks to me like your java classpath on the server is not set right...?What OS is OAS installed on?Do you have the same version of your Oracle application server on your computer and on the server?Did you set archive_jini variable in the formsweb.cfg?It could be a lot of things...

Unfortunately, last time I developed some JARs for Oracle forms application was more than a year ago, at work. And just developed...Some other people deployed my .jar to application server and set all the AS parameters...I don't remember they had any problems deploying it...

Thanks for your post. I have a problem to download the zip file with fmb and java source code because probably it's not available anymore. If you still have it I would appreciate if you can send me by email to alexander.reichman@gmail.comThanks