Returning value from Dialog

Hi
Can anyone share how can I obtain the selected entity from the dialog screen? For example, instead using a picker field, I want to use a Button in the 1st screen to popup a 2nd screen from where I want to select a record (in a table). After I have selected the record the 2nd table closes and I want to use the selected entity from the 2nd screen in 1st screen.

1 Like

Thank you for the good question. We will prepare a complete sample with various scenarios of programmatic manipulation with screens in the near future.
For now, look at the AccessionRegisterWindow screen in the Library sample, it has an example of returning a value from an editor screen:


public void createBook() {
    AbstractEditor bookEditor = openEditor(
            "library$Book.edit", metadata.create(Book.class), WindowManager.OpenType.THIS_TAB );
    bookEditor.addCloseListener(actionId -> {
        booksDs.refresh();
        bookField.setValue(bookEditor.getItem());
    });
}

So the idea is that you return a reference to the controller of the opened screen from openWindow(), openLookup(), openEditor() methods, and then add a CLoseListener to this reference. In the listener, you handle values after the screen is closed.
See also description of openWindow(), openLookup(), openEditor() methods here: https://doc.cuba-platform.com/manual-6.1/abstractFrame.html

We have added an example of programmatic screen manipulation to GitHub: https://github.com/cuba-platform/sample-screen-manipulation. So your problem is demonstrated here.
The sample project is also available on the Samples tab in Studio.

Hi
Thank you so much for that example. I have bought the license today and testing it in the latest version of the studio.

If you can also -

  1. Add use of similar functionality from the order line table, say for example, select Products,
  2. Take parameter from the order entity to product dialog where i can use it being part of Product entity e.g. customer
    that will be also very helpful.

> 1) Add use of similar functionality from the order line table, say for example, select Products,
Do you mean adding a row to the OrderLine table after selecting a Product?

> 2) Take parameter from the order entity to product dialog where i can use it being part of Product entity e.g. customer
Give me please an idea for a sensible attribute of Product that depends on Customer?

Hi

  1. Yes.
  2. I know what you mean. That is a common situation that the product is common to all customers. But there are some industries where it is not. This is applicable to those industries where a product is custom made for each customer based on the specifications given by the customer, for example, if you go to a tailor to make a shirt for you. You as a customer, may repeat the order later. In this case, the product is linked with customer and when we manage the customer orders, Products are filtered by Customer key. This example can be a good way to demonstrate how a parameter can be passed on to the UI called and used it.

Thanks for your help.

Hi Mortoza,
Thanks for the clarification. I will add the Customer parameter when opening Products screen and select Products that have a reference to this Customer and those without Customer reference, hence available for all.

Done.
See https://github.com/cuba-platform/sample-screen-manipulation or download the screen-manipulation sample in Studio.

That’s awesome. !!! Thank you for this sample solution.