Auto-Fill Customer name to Project Editor when clicking create from Customer Editor.

I am looking for a solution to setting an initial value to a drop-down field on a project editor screen when clicking create from a previously selected related Customer editor screen (See attached picture). It should automatically populate with the customers name for the project editor when clicking create from the previous screen. Furthermore, when creating a project directly from a project browser screen, I would still like to be able to choose a customer for this drop down field, which I am able to do now. I hope this makes sense. Thanks for the help.


1 Like

Solved it with the following code placed in my customer-edit controller:


import com.haulmont.bali.util.ParamsMap;
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.haulmont.cuba.gui.components.actions.CreateAction;
import com.haulmont.cuba.gui.components.actions.EditAction;

import javax.inject.Named;
import java.util.Map;

public class CustomerEdit extends AbstractEditor<Customer> {

    private CreateAction projectsTableCreate;
    public void init(Map<String, Object> params) {
        // Disable notification on saving entity without closing the screen
    protected void postInit() {
        // Get currently edited customer
        Customer customer = getItem();
        // Enable "create" action only if the edited customer is saved to the database
        // Pass the currently edited customer to be set to the "customer" attribute of a newly created project
        projectsTableCreate.setInitialValues(ParamsMap.of("customer", customer));

Thank you for posting the solution.