4.3.3. Returning Values from an Invoked Screen
The methods used for opening screens (openWindow(), openLookup(), openEditor()) also allow you to get values back from these screens.
- Returning a value from lookup screen
-
The
openLookup()method accepts a handler for the items selected in the opened lookup screen. In our example, the handler implemented by the lambda expression sets the selected customer for the editedOrderinstance.openLookup("sample$Customer.browse", items -> { if (!items.isEmpty()) { getItem().setCustomer((Customer) items.iterator().next()); } }, WindowManager.OpenType.DIALOG.setWidth("600px").setHeight("400px")); - Returning a value from an arbitrary screen
-
The idea is that you return a reference to the controller of the opened screen, and then add a
CloseListenerto this reference. In the listener, you handle the values after the screen is closed.OrderEdit screen controller demonstrates two ways of looking up a Customer: from a lookup screen and from an arbitrary screen, both returning a
Customerinstance.The
openWindow()method in the following example will open the customers list screen as a dialog window.CloseWithCommitListenerwill be notified when the screen is closed by action withWindow.COMMIT_ACTION_ID. This listener will be used to set the selected customer for the editedOrderinstance.CustomerList window = (CustomerList) openWindow("customer-list", WindowManager.OpenType.DIALOG); window.addCloseWithCommitListener(() -> { getItem().setCustomer(window.getSelectedCustomer()); });