Technical Notes |
|
Reflection for the Web provides an extensive API (Application Programming Interface) that enables users to automate many tasks. This technical note demonstrates the preferred method for ensuring that the Reflection for the Web session is initialized before calling methods on the API.
Use one of the following options to determine if the session is initialized.
This is the preferred method for determining that the session is initialized.
For more information about the JSEventNotifier, see the Reflection for the Web Software Development Kit (SDK) or view the "Using Notification to Determine When Reflection is Initialized" sample in the "API Examples" section of the Reflection for the Web help.
When using the Reflection API to create automated login tasks, it is important to ensure that the Reflection API is initialized before the API call is made, or the login task will fail.
Use one of the following options to call the Reflection for the Web API.
This is the preferred method for calling the API.
This method is less reliable, as it may fail to load the API in some conditions, such as on page reload.
The following sample script uses the ECL attachment class JSEventNotifier to make sure the session is fully initialized, then calls the Reflection for the Web API using "notifier.getECLSession()getJSAPI();"
Note: To use this sample, change the hostURL parameter in the <applet> tag to a host appropriate for your network.
<html><head><title>Example of using Notification to Determine Reflection Initialization</title><script language="JavaScript"><!-- /* Variable to hold the API reference when it's retrieved. */ var api = null; /* ECLInitComplete is the predefined name of the function that the com.wrq.eNetwork.ECL.modules.JSEventNotifier module calls when Reflection initialization is complete. It passes a reference to itself, which is not needed here. */ function ECLInitComplete( notifier ) { api = notifier.getECLSession().getJSAPI(); if ( api == null ) { alert( "Reflection API initialization failed." ); } else { doSessionSetup(); } } /* This function calls Reflection's showDialog method to open the Session Setup dialog box. This function is invoked only after notification is received that the terminal session has been initialized. */ function doSessionSetup() { api.showDialog( "sessionConfigure" ); }// --></script></head><!-- The onLoad event handler is used to execute the JavaScript code after the page is loaded.--><body><!-- This is the tag that launches a Reflection IBM 3270 applet. The archive attribute is used for Netscape browsers, while the cabbase parameter is used for Internet Explorer. To use this example, change the hostURL parameter to one appropriate for your network.--><applet mayscript name="IBM3270" codebase="./ex/" code="com.wrq.rweb.Launcher.class" width="666" height="448" archive="Launcher.jar"> <param name="hostURL" value="tn3270://accounts"> <param name="autoconnect" value="false"> <param name="cabbase" value="Launcher.cab"> <param name="launcher.sessions" value="IBM3270"> <param name="onStartupJavaClass" value="com.wrq.eNetwork.ECL.modules.JSEventNotifier"> <param name="preloadJSAPI" value="true"></applet></body></html> |