How To Implement A Similar Function In Web Forms For "WIN_API_SHELL.SENDKEYS"

How To Implement A Similar Function In Web Forms For "WIN_API_SHELL.SENDKEYS"

How To Implement A Similar Function In Web Forms For "WIN_API_SHELL.SENDKEYS"

Titleimage

Posted by Patrick Hamou on 2016:04:20 01:48:33

Applies to

Oracle Forms - Version: 10.1.2 and later   [Release: 10.1.2 and later ]
Information in this document applies to any platform.
Checked for relevance on 15-Aug-2010

Browser-less access to Oracle Forms 12c

Goal

This document explains how to implement a similar function in web forms for "WIN_API_SHELL.SENDKEYS" that was used in Forms Client/ Server version.

The java class "Robot" can be used to implement a similar function in Java. This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. 

The following references might be useful to understand and build your first java code:

  1. Oracle9i Forms in a Java World (This white paper applicable also for version 10.1.2.0.2)
  2. Oracle Forms / Java tutorial - How to build a new JavaBean
  3. Oracle9i Forms - Developing PJCs a Quickstart 


The following also is a sample code that simulates keys: "Enter" and "End" when the forms item 
gains focus. You can also download the sample code from here.

Solution

1. Create the following java file "SetFocus.java"

----------- SetFocus.java ----------------
import java.awt.Component; 
import java.awt.event.FocusAdapter; 
import java.awt.event.FocusEvent; 
import java.awt.im.InputContext; 

public class SetFocus extends FocusAdapter 
{ 
  public SetFocus() { 
  } 
  public void focusGained(FocusEvent fe) { 
    Component c = fe.getComponent(); 
    InputContext inputContext = c.getInputContext(); 
  } 
}

2. Create the following java file "FocusTextItem.java"

----------- FocusTextItem.java ----------------

import java.awt.AWTException; 
import java.awt.Robot; 
import java.awt.event.KeyEvent; 
import java.awt.im.InputContext; 
import oracle.forms.handler.IHandler; 
import oracle.forms.ui.VTextField; 
import oracle.forms.properties.ID; 

public class FocusTextItem extends VTextField { 
public final static ID KEYEND = ID.registerProperty("KEYEND"); 

static int keyInput[] = { 
   KeyEvent.VK_END 
}; 
static SetFocus focusAdapter; 
public void init(IHandler ih) 
{ 
  super.init(ih); 
  focusAdapter = new SetFocus(); 
  this.addFocusListener(focusAdapter); 
  System.out.println ("<< Init Text Item >>"); 
} 

public boolean setProperty(ID property, Object value) { 
  if(property == KEYEND) { 
    System.out.println ("<< \"End\" property >>"); 
    try{ 
        Robot robot = new Robot(); 
        robot.keyPress(KeyEvent.VK_END); 
    } 
    catch (AWTException e)  { System.out.println(e.getStackTrace()); } 
  return true ; 
  } 
  else  { 
    return super.setProperty(property, value); 
  } 
 } 
}

3. Create the following java file "FocusTextArea.java"

---------------FocusTextArea.java--------------------
import java.awt.AWTException;  
import java.awt.Robot;  
import java.awt.event.KeyEvent;  
import java.awt.im.InputContext;  
import oracle.forms.handler.IHandler;  
import oracle.forms.ui.VTextArea;  
import oracle.forms.properties.ID;  

public class FocusTextArea extends VTextArea  
{  
public final static ID KEYEND = ID.registerProperty("KEYEND");  

  static int keyInput[] = {  
     KeyEvent.VK_END  
  };  
static SetFocus focusAdapter;  
public void init(IHandler ih)  
{  
   super.init(ih);  
   focusAdapter = new SetFocus();  
   this.addFocusListener(focusAdapter);  
   System.out.println ("<< Init Text Area >>");  
}  

public boolean setProperty(ID property, Object value)  
{  
    if(property == KEYEND)  
    {  
    System.out.println ("<< \"End\" property >>");  
      try{  
      Robot robot = new Robot();  
      robot.keyPress(KeyEvent.VK_END);  
      }  
      catch (AWTException e)  
      { System.out.println(e.getStackTrace()); }  
    return true ;  
    }  

    else  
    {  
       return super.setProperty(property, value);  
    }  
 }  
} 

4. Create the following java file "PressButton.java"

----------- PressButton.java ----------------

import java.awt.AWTException;  
import java.awt.Robot;  
import java.awt.event.KeyEvent;  
import java.awt.im.InputContext;  
import oracle.forms.handler.IHandler;  
import oracle.forms.ui.VButton;  
import oracle.forms.properties.ID;  

public class PressButton extends VButton {  
  public final static ID KEY_ENTER = ID.registerProperty("ENTER");  
  static int keyInput[] = {  
  KeyEvent.VK_ENTER  
};  

static SetFocus focusAdapter;  
public void init(IHandler ih)  
{  
  super.init(ih);  
  focusAdapter = new SetFocus();  
  this.addFocusListener(focusAdapter);  
  System.out.println ("<< Init Push Button >>");  
}  

  public boolean setProperty(ID property, Object value)  
  {  
   
    if(property == KEY_ENTER)  {  
      System.out.println ("<< \"Enter\" property >>");  
      try{  
      Robot robot = new Robot();  
      robot.keyPress(KeyEvent.VK_ENTER);  
      }  
      catch (AWTException e) {  
      System.out.println(e.getStackTrace());  
      }  
    return true ;  
    }  
    else {  
    return super.setProperty(property, value);  
    }  
  }  
} 

5) Compile the java files to generate .class files

  1. Open command prompt and navigate to the directory where .java files exist
  2. Run the following commands
set CLASSPATH=%ORACLE_HOME%\forms\java\frmall.jar;%CLASSPATH%  
set ORACLE_HOME=path to your oracle home  
%ORACLE_HOME%\jdk\bin\javac SetFocus.java   
%ORACLE_HOME%\jdk\bin\javac FocusTextItem.java   
%ORACLE_HOME%\jdk\bin\javac FocusTextArea.java   
%ORACLE_HOME%\jdk\bin\javac PressButton.java

6. Create a jar file for the classes

%ORACLE_HOME%\jdk\bin\jar -cvf myKeys.jar SetFocus.class FocusTextItem.class FocusTextArea.class PressButton.class

7. Sign and copy the new jar file "myKeys.jar" to

%ORACLE_HOME%\forms\java

8. Edit the file %ORACLE_HOME%\forms\server\formsweb.cfg and add the following configuration section

[myKeys]
archive=frmall.jar,myKeys.jar
baseHTMLJInitiator=basejpi.htm

-OR -

if you are using JInitiator, add the following:

[myKeysJinit] 
archive_jini=frmall_jinit.jar,myKeys.jar 
baseHTMLjinitiator=basejini.htm

The Java class Robot works since java version 1.3 and higher

9. Create a new form and add the following items and  make it visible on the Canvas

(a) DUMMY

(Property / Value)
Name: DUMMY
Item Type: Text Item
Width: 0
Height: 0

Make sure item "DUMMY" is the first navigable item in the block

(a) TEXT_ITEM

(Property / Value)
Name: TEXT_ITEM
Item Type: Text Item
Implementation Class: FocusTextItem
Initial Value: This is a test text item!!

Create trigger WHEN-NEW-ITEM-INSTANCE for this item and add the following code:

Set_Custom_Property('CONTROL.TEXT_ITEM',1,'KEYEND','');

(b) TEXT_AREA

Property / Value
Name: TEXT_AREA
Item Type: Text Item
Multi-line: Yes
Implementation Class: FocusTextArea
Initial Value: This is a test text area!!

Create trigger WHEN-NEW-ITEM-INSTANCE for this item and add the following code:

Set_Custom_Property('CONTROL.TEXT_AREA',1,'KEYEND','');

(b) BUT_ALERT

Property / Value
Name: BUT_ALERT
Item Type: Push Button
Implementation Class: PressButton

Create trigger WHEN-NEW-ITEM-INSTANCE for this item and add the following code:

Set_Custom_Property('CONTROL.BUT_ALERT',1,'ENTER','');

Create trigger WHEN-BUTTON-PRESSED for this item and add the following code:

MESSAGE('Hello World');

10. Run the form using Sun JRE, and using the configuration section "myKeys", i.e.

http://machin:port/forms/frmservlet?config=myKeys&form=formname.fmx

11. Navigate to the items using the keyboard, you will notice that:

  • When navigating to the Text Item or the Text Area the cursor position will move to the end of the text (as a result of key End)
  • When navigating to the button, a message will be displayed (as a result of key Enter)

Posted by Patrick Hamou on 2016:04:20 01:48:33

Return to Blog