Oracle Forms - How to integrate Oracle Forms and JavaScript ?

How to integrate Oracle Forms and JavaScript ?

How to integrate Oracle Forms and JavaScript ?

Titleimage

Posted by RENAPS DBA Team on 2024:06:19 01:26:33

Oracle Forms - About Oracle Forms Calling External Events

In previous releases of Oracle Forms, you had to implement OLE and DDE to interact with a limited number of event types outside of Forms. In later versions, Forms offered web.show_document and Java integration to interface with external application sources.

But in terms of calling out to the Web page where Forms is displayed, there was no easy solution. It was also not possible to call from the Web page into Forms, perhaps to update a value acquired from an HTML form.

JavaScript integration provides the ability to have JavaScript events call into Forms, or have Forms execute JavaScript events. The following figure shows how JavaScript and Oracle Forms work together. In the left side of the image, JavaScript is executed in the page in which the Forms applet is hosted. Oracle Forms now has the capability to call JavaScript functions using native built-ins. Also, JavaScript functions can now trigger a Oracle Forms trigger by using a new API that has been provided.

Figure -22 Oracle Forms and JavaScript

Two new calls are available in the web Built-in package:

  • web.javascript_eval_expr
  • web.javascript_eval_function

The first call web.javascript_eval_expr is a procedure which takes two arguments: an expression and a target, both of data type varchar2. This legal JavaScript expression is interpreted in the Web page in which the Forms applet is embedded. The expression can be a call to a function that is defined in the target page or any valid JavaScript expression that can be executed on the target page, for example, document.bgColor='red'. The expression is executed, using LiveConnect's JSObject.eval() method, in the context of the page or frame that is named in the target argument. If the target argument is , then it is executed in the page or frame in which the Forms applet is embedded.

The second call, web.javascript_eval_function is a function and returns a varchar2 value. Both web.javascript_eval_expr and web.javascript_eval_function have the same functionality except that javascript_eval_expr does not send any return value from the Forms client to the Forms Services. If your application does not need a return value, use web.javascript_eval_expr. The additional network trip that is required to carry the return value from the Forms client to the Forms Services is eliminated.

To set the value of an HTML text item with the ID outside_field_id to the value of the Forms field called inside, you could write this PL/SQL code:

web.javascript_eval_expr('
document.getElementById("outside_field_id").value='
||:inside
);

Notice that the PL/SQL string must use single quotes while JavaScript is flexible enough to use single or double quotes. Using double quotes inside the expression works without having to use escape sequences. You could also write a function in the Web page:

<SCRIPT>
    function set_field(field_id, myvalue){
        document.getElementById(field_id).value=myvalue;
    };
</SCRIPT>

To get the value of the outside field and assign it to the inside field, you could write the following PL/SQL code:

:inside:=web.javascript_eval_function('
     document.getElementById("outside_field_id").value
     ');

Reason for Calling Events Outside of Oracle Forms

JavaScript functionality allows you to integrate Forms with HTML-based application technologies in the Web browser. For example you can use JavaScript integration when the Forms-based application is required to integrate on the page with new functionality based on an HTML front end.

About JavaScript Events Calling into Oracle Forms

You can also allow JavaScript calls into Oracle Forms by using JavaScript in the Web page that hosts the Forms applet.

There is new functionality available on the embedded Forms object in the DOM (Document Object Model) tree. You use JavaScript to do:

document.forms_applet.raiseEvent(event_name, payload);

The assumption here is that you have set the ID configuration variable to forms_applet.

When the surrounding Web page executes this JavaScript code, Oracle Forms fires a new type of trigger called WHEN-CUSTOM-JAVASCRIPT-EVENT. In this trigger there are only two valid system variables: system.javascript_event_value and system.javascript_event_name. These variables contain the payload and event name that were passed into Forms through the raiseEvent method. On calling the raiseEvent method, a trigger named WHEN-CUSTOM-JAVASCRIPT-EVENT is fired on the server side.

declare
    event_val varchar2(300):= :system.javascript_event_value;
begin
    if (:system.javascript_event_name='show') then
        handleShowEvent(event_val);
    elsif(:system.javascript_event_name='grab') then
	  handleGrabEvent(event_val);
    else
        ;
    end if;
end;

This PL/SQL code recognizes two events: 'show' and 'grab'. Any other name is ignored.

Reason to Let Events Call into Oracle Forms

You can synchronize an HTML based application, whether it is Java-based or otherwise, with a Forms-based application in the same hosting Web page. For example, you can use the HTML-based application to query data and use Forms to update it if, and only if, the user has the correct access privileges.

Integrating JavaScript and Oracle Forms

This section describes an example for integrating JavaScript in Oracle Forms application.

To integrate JavaScript in Oracle Forms applications, perform the following steps:

  1. Build a Forms application using the JavaScript events. Use the :system.javascript_event_name and :system.javascript_event_value in the WHEN-CUSTOM-JAVASCRIPT-EVENT trigger. Compile the module.
  2. Create an html file (for example, test.html) that the Forms servlet will use as a template when generating the HTML page used to start an Oracle Forms application. Copy the file to the Forms configuration directory: $ORACLE_INSTANCE/config/FormsComponent/forms/server
  3. Copy any required images, html files, JavaScript files, and css files to the following directory: $DOMAIN_HOME/servers/WLS_FORMS/tmp/_WL_user/formsapp_12.2.1//war/
  4. Create an html file that uses the JavaScripts (for example, js.html) and invokes the servlet URL.
  5. Using Enterprise Manager, create a new configuration section or modify an existing one and enable enableJavascriptEvent. Set baseHTMLjpi to test.html.
  6. Using Enterprise Manager, edit the default.env file and add the directory where you saved the forms application to the environment variable FORMS_PATH.
  7. Run the application by using the URL in your browser: http://:9001/forms/js.html

Forms and JavaScript Integration for Java Web Start and Forms Standalone Launcher

When using Java Web Start or Forms Standalone Launcher, it is possible to integrate with JavaScript using Forms Websocket JavaScript Integration (WJSI).

The ability to integrate a Forms application with a web page through JavaScript was introduced in Oracle Forms 11g R2. This feature allowed developers to blend Forms applications with HTML-based web applications. Forms applications were able to communicate with HTML pages, which resulted in more creative application designs. In releases earlier than 12.2.1.3, the ability to integrate through JavaScript was not possible when using Java Web Start or the Forms Standalone Launcher.  This is because those configurations do not have a parent browser, thereby exposing no way to connect between the two technologies.

Leveraging Eclipse/Jetty, an extremely lightweight web listener, a Forms application running with Java Web Start or the Forms Standalone Launcher can communicate with a web page through Web Socket connections.

This feature requires the download and signing of Jetty jar file, jetty-all-9.4.5.v20170502-uber.jar or newer from Eclipse. Download the jar file from the jetty-all directory at maven.org.

Note:Running Forms with Jetty versions newer than the 9.4 family will require using Java 11 or newer on the user's machine.

More information about Jetty can be found on the Eclipse web site.

In order to facilitate integration between a web page and a Forms application, in addition to the use of Eclipse or Jetty, each web page that is to be integrated must include the following HTML to the BODY of the web page:

<script src="/forms/java/frmwebsocketjsi.js"></script> 

If the web page is running from a different server than Forms, use a fully qualified path to address the Forms environment.

Note: Altering the contents of frmwebsocketjsi.js is not supported or recommended. It is also not recommended that this file be moved from its default location, as doing so will prevent patching from properly updating the file if necessary.

Web Configuration for JavaScript Integration

The administrator of the Forms application can enable or disable JavaScript integration by setting the parameter enableJavascriptEvent in formsweb.cfg to "true" or "false".

If enableJavascriptEvent is not set to true, then calls from JavaScript would be ignored. The applet_name parameter must be set to the value that is used by the HTML developer to reference the forms applet via document.<applet_name>.

The administrator can also set JavaScriptBlocksHeartBeat (default value is false) in formsweb.cfg to true. This blocks Form's HEARTBEAT during the time JavaScript is executed. If the JavaScript calls complete execution before the FORMS_TIMEOUT period, setting JavaScriptBlocksHeartBeat to true provides an increase in performance by avoiding additional network messages.

Notice that if JavaScriptBlocksHeartBeat is set to true, Forms would abnormally terminate if the time taken for executing a JavaScript is more than FORMS_TIMEOUT.

The following Web configuration parameters can be optionally used with the WJSI configuration explained in the section above.

websocketJSILogging

websocketJSIServerTimeout

websocketJSISessionTimeout

Configuring Environment Variables

An environment variable called FORMS_ALLOW_JAVASCRIPT_EVENTS in default.env is also used to enable or disable JavaScript integration.

By default, the value of the variable is true. If this is set to false, then JavaScript integration is not enabled for any Forms application that uses that instance of default.env, no matter what value is set for enableJavascriptEvent in formsweb.cfg.

The FORMS_WJSI_OVERRIDE_TIMEOUT environment variable can be optionally used with the WJSI configuration explained in the section above.

Oracle Forms Upgrade: Automate your Oracle Forms Upgrade process with ORMIT™-Forms

ORMIT™-Forms automates every Oracle Forms Upgrade from all earlier versions to the latest versions.

ORMIT™-Forms guarantees the overall success of your Oracle Forms Upgrade with an emphasis on efficiency, cost and time savings, eliminating any potential risk. The automated process is extremely fast and secure. It automates a large quantity of actions while eliminating the guess work associated with manual upgrades. ORMIT™-Forms also minimizes downtime and identifies manual tasks that require DBA action.

Posted by RENAPS DBA Team on 2024:06:19 01:26:33

Return to Blog