Need help updating valuesource of generated components on a table

I have a table and I have generated 2 combo boxes … great… but now if one combo box changes I need to change the value source of the combo box beside it. How can I achieve this in a table. I’m using Jmix 1.5.
thank you.

Hello Eduardo!

Could you clarify do you need to change options in dropdown list of ComboBox in second column while changing value in ComboBox in the first column?

Yes one of the comboxes has a query that is dependent on the value that the other combo box beside it has. both of these combo boxes are generated. I have no idea how to pull the right combo box from the right record and change its values after running a query from the value of the other one.

If your columns are bound with properties in an entity, you can rely on value of the changed property.

Lets say, there is a “country” and “city” columns with generated ComboBox. If country changed we should change options in “city” ComboBox.

After the user selected “country 1”, a table is repainted and column generators are invoked again (several times). Thus in “city” column generator we should check the “country” value that is saved in entity instance.

For example:

@Install(to = "locationsTable.city", subject = "columnGenerator")
protected Component locationTableCityColumnGenerator(final Location location) {
    ComboBox<String> component = uiComponents.create(ComboBox.NAME);

    InstanceContainer<Location> instanceContainer = locationsTable.getInstanceContainer(location);
    component.setValueSource(new ContainerValueSource<>(instanceContainer, "city"));

    // Get "country" value and load options
    component.setOptionsList(getOptionsFor(location.getCountry()));
    return component;
}

protected List<String> getOptionsFor(String country) {
    // ...
}
1 Like

Works !!! Thank you so much for solving my problem!