program MyUIProgram type UIProgram {inputUIRecord = myInitialContainer}
// the Record parts for the following two declarations are shown
// in a later description of the "gateway record" data property
myInitialContainer InitialContainer;
myRepeatedContainer RepeatedContainer;
endCondition Boolean = false;
start, end Int;
myDataArray MySQLRecord[];
function main()
while (endCondition == false)
// The logic retrieves data (not shown)
// and determines what portion to send.
for (i int from start to end)
myRepeatedContainer.sendList[i] = myDataArray[n];
n = n + 1;
end
// no explicit JSON conversion is required here.
converse myRepeatedContainer;
// set endCondition in response to an input value
end
end
end
In this case the while loop ends when the program sets the end condition in response to a particular value from the requester. In an alternative case, the while loop ends when the requester invokes ServiceLib.endStatefulServiceSession. That second option is not recommended, particularly in the following case: the requester of the gateway service is a Rich UI application, and the EGL Rich UI proxy is in the same session as the UI program. In that case, ending the UI program by invoking the ServiceLib.endStatefulServiceSession function also ends the Rich UI application's ability to access services.
program MyOtherUIProgram type UIProgram {}
const MENU_FORM int = 0;
const FORM_ONE int = 1;
const FORM_TWO int = 2;
// the Record parts are not shown
myMenuContainer MenuContainer; // holds an integer: a menu choice
myFormOneContainer FormOneContainer; // holds data for form 1, with the form ID
myFormTwoContainer FormTwoContainer; // holds data for form 2, with the form ID
endCondition Boolean = false;
formNumber Int = MENU_FORM;
function main()
while (endCondition == false)
case (formNumber)
when (MENU_FORM)
converse myMENUContainer;
// process in some way and set formNumber
when (FORM_ONE)
converse myFormOneContainer;
// process in some way and set formNumber
when (FORM_TWO)
converse myFormTwoContainer;
// process in some way
endCondition = true;
otherwise
// throw an exception
end
end
end
end
When you work with the EGL Deployment Descriptor editor to deploy the UI gateway service as a Web service, a deployment-descriptor entry is made available to you as if you had coded the service. To deploy a stateful EGL REST-RPC service, you can specify that the service is stateful in the Service Deployment tag of that editor.
A complete UI program example is available to you in “End-to-end processing with a UI program and a data grid.”
As noted in the next section, the requester passes and receives business data in JSON format, and the JSON string is embedded in a field of a record that is of type UIGatewayRecord. In general, you handle a record of this type when you code a requester but not when you code a UI program.
Record UIGatewayRecord
uiProgramName STRING;
data STRING;
dataEncoding EncodingKind;
terminated Boolean;
end
gateRec.uiProgramName = "myPkg.Translate";
When the service responds to the requester, the service ensures that the field value represents the next EGL part to invoke, if any. Again, you typically do not update the gateway record explicitly in the UI program.
Record InitialContainer
initialValue INT;
end
Record RepeatedContainer
numberOfRecords INT;
pageNumber INT = 1;
sendList theSQLRecord[]{};
end
gatewayServiceVar UIGatewayService{@BindService{bindingKey="UIGatewayService"}};
http://localhost:8080/MyWebProject/restservices/uiGatewayService
gateRec UIGatewayRecord;
gatewayRec.data = ServiceLib.convertToJSON( sendToProgram );
The string reflects the content that is intended for the UI program.
call gatewayServiceVar.invokeProgram(gateRec)
returning to callbackFunc onException handleException;
function invokeProgram(gatewayRecord UIGatewayRecord INOUT);
function callbackFunc(gatewayRecord UIGatewayRecord in)
For the requester that is responding to a UI program converse statement, the structure of the data field content in the received gateway record must be equivalent to the structure of the data field content sent back to the UI program. Only the content of the data can vary.
The data sent to the UI program includes the fully qualified name of the EGL part to invoke; that is, the data includes the package name and part name. If the part has an alias, the alias is used in place of the part name. The part might be another UI program or might be an EGL library.
ServiceLib.convertFromJSON( gatewayRecord.data, dataRecord);
EGL2156E The session associated with program MyUIProgram was invalidated.
The requester uses JSON conversion functions, but the UI program typically does not.
Receipt of data into the record does not involve a JSON conversion function. The conversion is handled for you.
A show statement is valid in a library only when the library is invoked from a UI program.
The data sent by a particular converse statement must be structured like the data received by that statement.
The show and converse statements do not use a JSON conversion function. The required conversions are handled for you, including the conversion that occurs after the converse statement, when the requester re-invokes the program and causes the program to process the statement that follows the converse statement.
The benefit of accepting the default value is that you free application-server resources during user think time. However, the effect of the program exit might require additional coding because the EGL runtime code closes files and database connections, releases libraries, and resets the value of those EGL system variables that are not saved across a converse statement.
For additional details, see “Segmentation in Text UI programs and UI programs.”
When you generate the UI program, ensure that the j2ee build descriptor option is set to yes.
Record MyException type Exception end
Program MyUIProgram type UIProgram {}
function main()
try
// get an array of data from a relational database
get mySQLRecord;
onException(except AnyException)
throw new MyException{message =
"Error at get mySQLRecord: " + except.message};
end
end
end
If the UI program times out during an ongoing conversation with a requester, the exception is returned the next time that the requester invokes the program.