Create entity from editor screen without persisting Cuba 7

Is it possible to invoke an editor screen then create the entity and pass it back without persisting to the database?

I have a base entity with a composition of say “Customers” and I do not want the customer to be persisted unless the base entity is persisted.

@Inject
private CollectionPropertyContainer<Customer> customersDc;


private void addNewCustomer() {
  
Customer customer = new Customer();
customer.set ...

    screenBuilders.editor(Customer.class, this)
            .editEntity(entity)
            .build()
            .show().addAfterCloseListener(afterCloseEvent -> {
                myDc.getItems.add(customer) );
    });
}

Nevermind I have resolved.

You can assign the table to the screenbuilder

CustomerEditScreen customerEditScreen  = screenBuilders.editor(customersTable)
                    .newEntity()
                    .withInitializer(customer-> {          // lambda to initialize new instance
                        customer.setName("Some Name");

                    })
                    .withScreenClass(CustomerEditScreen.class)    // specific editor screen
                    .withLaunchMode(OpenMode.THIS_TAB)        // open as modal dialog
                    .build();

            customerEditScreen.setSomeSetterMethod(someValue.getSomeValue());
            customerEditScreen.show();

        }
2 Likes