display.open()

display.open()

Description

display.open() opens a Rich Display File that was defined with the userOpen option set to true in the pjs.defineDisplay() call. A display file defined without userOpen is opened implicitly, so this method is only needed when the module controls the open itself, in the same way as the RPG USROPN keyword and OPEN operation.

When the file is opened, the file feedback area of the infDS data structure (if one was defined) is updated with the file name, open indicator, ODP type, library, and requester name. The display object is registered with the session so that its screens can be written to the browser.

Syntax

display.open()

Parameters

None.

Return Value

Nothing is returned.

If the display file is already open, display.open() throws error 1215 (OPEN issued to a file already opened). Use display.isOpen() to test the state first when the open may already have happened.

Examples

Example 1: Open and Close a Display File Explicitly

Defines the display with userOpen: true, so nothing is opened until display.open() is called. The screen is used between the open and close.

Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.

pjs.defineDisplay("display", "customer.json", { userOpen: true }); display.open(); // The file must be opened before any screen I/O custname = "ACME Corporation"; display.detail.execute(); // Show the screen and wait for the response display.close(); // Close the file when it is no longer needed

Example 2: Avoid Opening a File Twice

A helper function that several parts of a module can call safely. display.isOpen() prevents the 1215 error that would occur if the file were already open.

Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.

pjs.defineDisplay("display", "customer.json", { userOpen: true }); function showCustomer(number) { if (!display.isOpen()) { // Only open the file the first time display.open(); } custno = number; display.detail.execute(); } showCustomer(1001); showCustomer(1002); // The file is already open, so open() is skipped display.close();

Example 3: Handle the Already-Open Error

Shows what happens when display.open() is called on a file that is already open. The error is caught and its status code is written to the console.

Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.

pjs.defineDisplay("display", "customer.json"); // Opened implicitly try { display.open(); // The file is already open... } catch (error) { console.log(error.message); // ...so error 1215 is thrown: OPEN issued to a file already opened }

RPG Equivalent

OPEN


Related Pages