Using JAVA APIs to create an Oracle FORM (FMB) December 26th 2005
This really an interesting idea. In this example, a new Oracle form will be created (ie replacing Forms Builder); It is going to be based on the DEPT block and contain the three fields in that table. another example will open the created form and modifies one of the prompts
Note: This was tested against Oracle Forms builder 10g MORE..
Note: you will need to add the the frmjdapi.jar to your project. the file is normally located at the following path
$FORMS_HOME/forms/java
Exmaple : Create a form from scratch
package model;
import oracle.forms.jdapi.*;
public class deptform
{
public static void main(String[] args)
{
// Create a form Module.
FormModule fmb = new FormModule("myform.fmb");
//Create the Canvas
Canvas Department = new Canvas(fmb,"DEPARTMENT");
// Create a form level trigger Ammar
Sajdi
try
{
Trigger trg = new Trigger( fmb, "ON-LOGON" );
trg.setTriggerText("LOGON('scott','tiger@orclSTC');" );
}
catch( Exception exc)
{
exc.printStackTrace();
}
//Create the Block
Block Dept = new Block(fmb,"DEPT");
Dept.setQueryDataSourceName("dept"); // block is based on Dept table
//Create the first item - Deptno
Item Deptno = new Item(Dept,"DEPTNO");
Deptno.setDataType(1);//Number
Deptno.setMaximumLength(3);
Deptno.setRequired(true);
//Canvas name must be upper case
Deptno.setCanvasName("DEPARTMENT");
Deptno.setXPosition(47);
Deptno.setYPosition(30);
Deptno.setWidth(27);
Deptno.setHeight(14);
Deptno.setPrompt("Deptno");
Deptno.setPromptAttachmentOffset(2);
Deptno.setColumnName("Deptno");
// Next , item definitions and properties
//Create Item Dname
Item Dname = new Item(Dept,"DNAME");
Dname.setDataType(0);//Char
Dname.setMaximumLength(14);
Dname.setRequired(false);
Dname.setCanvasName("DEPARTMENT");
Dname.setXPosition(110);
Dname.setYPosition(30);
Dname.setWidth(27);
Dname.setHeight(14);
Dname.setPrompt("Dname");
Dname.setPromptAttachmentOffset(2);
Dname.setColumnName("dname");
//Create item LOC
Item Loc = new Item(Dept,"LOC");
Loc.setDataType(0);//char
Loc.setMaximumLength(13);
Loc.setRequired(false);
Loc.setCanvasName("DEPARTMENT");
Loc.setXPosition(160);
Loc.setYPosition(30);
Loc.setWidth(27);
Loc.setHeight(14);
Loc.setPrompt("Loc");
Loc.setPromptAttachmentOffset(2);
Loc.setColumnName("loc");
fmb.save("c:\\amm.fmb");
// finally, free API resources
Jdapi.shutdown();
}
}
Example (2) modify an existing form added on
Nov 19. 2008
package project1;
import oracle.forms.jdapi.*;
public class Class1
{
public Class1()
{
System.out.println("starting modification");
FormModule fmb = FormModule.open("c:\\realsoft.fmb");
JdapiIterator blocks = fmb.getBlocks();
while (blocks.hasNext()) {
// Block myblock = (Block)fmb.getBlocks();
Block myblock = (Block)blocks.next();
JdapiIterator items = myblock.getItems();
while (items.hasNext())
{
System.out.println("inside items");
Item myitem = (Item)items.next();
System.out.println(myitem.getName().toString());
if (myitem.getName().equals("LOC"))
{
System.out.println("before change label");
myitem.setPrompt("AMMAR1");}
}
}
System.out.println("done");
fmb.save("c:\\realsoft.fmb");
System.out.println("done");
Jdapi.shutdown();
}
public static void main(String[] args)
{
Class1 class1 = new Class1();
}
}