Passing Variable to the next screen?

Hi, I have a list of customers and they may have several delivery addresses. So in the customer edit, I have a table with all the address this particular customer have with a button to create a new address. When I click on create, it opens the address edit screen where I fill out the info. However, it ask me to pick the customer that this new address belongs to. Since I was already in this customer record, when I click on new address, I want the current customer ID to be passed to the new address screen so that the user don’t have to choose the customer. That should be automatic. I can’t figure how to get this to work. Can you help?

Hi,

generally you can pass parameters to an editor via the parameters attribute in the openEditor method.
In your case when you have a existing table, you probably don’t call openEditor explicitly. Instead you can get a receive the existing “create” action from the table via


class CustomerEdit extends AbstractEditor {
  @Inject
  Table<Customer> customersTable;

  @Override
  public void init() {
    CreateAction createAction = customersTable.getAction("create");
    createAction.setWindowParams(/* ... */ )
 }
}

But in your case, you don’t even need that manual passing of the customer as an attribute. When you model your entity relationship as a Composition in the following way: Customer -Composition-> Address, the described behavior is the default.

An example of this can be found here: GitHub - mariodavid/cuba-ordermanagement: Example project for ordermanagement in CUBA

There we have a Order -Composition-> OrderLine, which is basically the same thing.

Bye
Mario

And if you don’t have a composition but standalone editors, you can initialize attributes of created entity using setInitialValues method of the “create” action. See an example in the postInit() method here.