In this post I will show how a java component can be plugged in to an Oracle Form. The main problem in achieving this, it's Oracle poor reference for the framework that allows this kind of integration. All you can do it's search the internet and look for as many articles as possible. In the following article I'll create a simple JavaBean component which will send a string to Oracle Forms.
Pasul 1 este sa adaugati o referinta catre frmall.jar care se gaseste in locul in care ati instala Oracle Developer Suite/forms/java.
Step 1: you have to add frmall.jar library reference to your classpath. You can find this library in $ORACLE_HOME/forms/java(in case you installed only Oracle Developer Home) or in $DevSuiteHome_x/forms/java(in case you have installed the Oracle DB and Oracle Developer Suite).
Step 2: You have to compile the following class:
package ro.javabeans;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.CustomEvent;
import oracle.forms.ui.VBean;
public class HelloWorld extends VBean
{
private static IHandler myHandler;
protected static final ID MESAJ = ID.registerProperty("MESAJ");
private String msg;
public void setMsg(String s)
{
this.msg = s;
}
public String getMsg()
{
return this.msg;
}
public void init(IHandler handler)
{
myHandler = handler;
super.init(handler);
}
public boolean setProperty(ID property, Object value)
{
if(property == MESAJ)
{
this.setMsg((String)value);
return true;
}
return super.setProperty(property, value);
}
public Object getProperty(ID property)
{
if(property == MESAJ)
return this.getMsg();
return super.getProperty(property);
}
public void dispatchEvent(ID id)
{
CustomEvent ce = new CustomEvent(myHandler, id);
dispatchCustomEvent(ce);
}
}
Comments:
I think I have to explain the code a little. First of all, every JavaBean which has to run in Oracle Forms has to subclass VBean. We set myHandler, because this object give us methods to access Oracle Forms environment.
protected static final ID MESAJ = ID.registerProperty("MESAJ"). This line register a bean property which can be used in PL/SQL code using set_custom_property/get_custom_property functions. The name of the property is case sensitive, so I recommend you use just capital letters or lower letters(it's up to you).
setProperty/getProperty method are callback functions invoked by the framework to return a property or set a property from Oracle Forms.
dispatchEvent method is used to implement custom events that can be raised/received from Oracle Forms.
Step 4: exporting the project to a jar archive in $DevsuiteHome/forms/java.
Step 5: You need to modify under DevsuiteHome/forms/server/formsweb.cfg, entry archive=....,exported_project.jar
Step 6: We create a new form and we add a JavaBean item. We change its implementation class property to ro.javabeans.HelloWorld
Step 7: We add a when-new-form-instance trigger with the following code:
declare
msg VARCHAR2(200) := 'Va pup pe toti';
begin
SET_CUSTOM_PROPERTY('BLOCK3.BEAN4', 1, 'MESAJ', 'SALUTARI');
end;
Comments:
I assume that JavaBean item it's located unde BLOCK3 and it's named BEAN4. SET_CUSTOM_ATTRIBUTE is a builtin used to set attributes for a bean.
Step 8: We add a button on the canvas.
Step 9: We add trigger when-mouse-click, with the following code:
declare
msg VARCHAR2(2000) := GET_CUSTOM_PROPERTY('BLOCK3.BEAN4', 1, 'MESAJ');
begin
MESSAGE(msg);
end;
Step 10: We ran the application as a normal Oracle Forms application.
That's all. It's easier than it looks like. I hope this post helped you in your work.
Abonați-vă la:
Postare comentarii (Atom)
Niciun comentariu:
Trimiteți un comentariu