RelatedAction

RelatedAction is a list action designed to open a browser screen with the list of related entities. Related entities are selected considering the user permissions for entities, entity attributes and screens.

A browser screen with the list of related entities should contain the filter component.

The action is implemented by the io.jmix.ui.action.list.RelatedAction class and should be defined in XML using type="related" action’s attribute. You can configure common action parameters using XML attributes of the action element. See Declarative Actions for details. Below we describe parameters specific to the RelatedAction class.

Properties

The following parameters can be set both in XML and in Java:

  • openMode - the lookup screen opening mode as a value of the OpenMode enum: NEW_TAB, DIALOG, etc. By default, RelatedAction opens the lookup screen in THIS_TAB mode.

  • screenId - string id of the lookup screen to use. By default, RelatedAction uses either a screen, annotated with @PrimaryLookupScreen, or having identifier in the format of <entity_name>.browse, for example, demo_Order.browse.

  • screenClass - Java class of the lookup screen controller to use. It has a higher priority than screenId.

  • property - the property from which you want to show related entities.

  • configurationName - the caption that will be set to filter in the opened screen.

For example, if you want to open a specific lookup screen as a dialog, you can configure the action in XML:

<action id="related" type="related">
    <properties>
        <property name="property" value="favoriteBrands"/>
        <property name="openMode" value="DIALOG"/>
    </properties>
</action>

Alternatively, you can inject the action into the screen controller and configure it using setters:

@Named("customersTable.related")
private RelatedAction relatedAction;

@Subscribe
public void onInit(InitEvent event) {
    relatedAction.setOpenMode(OpenMode.DIALOG);
    relatedAction.setProperty("favoriteBrands");
}

Handlers

Now let’s consider parameters that can be configured only in Java code. To generate correctly annotated method stubs for these parameters, use Studio.

screenOptionsSupplier

It is a handler that returns the ScreenOptions object to be passed to the opened lookup screen. For example:

@Install(to = "customersTable.related", subject = "screenOptionsSupplier")
private ScreenOptions customersTableRelatedScreenOptionsSupplier() {
    return new MapScreenOptions(ParamsMap.of("someParameter", 10));
}

The returned ScreenOptions object will be available in the InitEvent of the opened screen.

screenConfigurer

It is a handler that accepts the lookup screen and can initialize it before opening. For example:

@Install(to = "customersTable.related", subject = "screenConfigurer")
private void customersTableRelatedScreenConfigurer(Screen screen) {
    ((BrandBrowse) screen).setSomeParameter(10);
}

Note that screen configurer comes into play when the screen is already initialized but not yet shown, that is, after its InitEvent and AfterInitEvent and before BeforeShowEvent are sent.

afterCloseHandler

It is a handler that is invoked after the lookup screen is closed. AfterCloseEvent is passed to the handler. For example:

@Install(to = "customersTable.related", subject = "afterCloseHandler")
private void customersTableRelatedAfterCloseHandler(AfterCloseEvent afterCloseEvent) {
    System.out.println("Closed with " + afterCloseEvent.getCloseAction());
}

Using ActionPerformedEvent

You can also subscribe to ActionPerformedEvent, and instead of invoking the action’s execute() method, use RelatedEntitiesBuilder API directly to open the browser screen. For example:

@Subscribe("customersTable.related")
public void onCustomersTableRelated(Action.ActionPerformedEvent event) {
    RelatedEntitiesBuilder builder = relatedEntitiesSupport.builder(this);
    Screen brandBrowser = builder
            .withMetaClass(metadata.getClass(Customer.class))
            .withProperty("favoriteBrands")
            .withSelectedEntities(customersTable.getSelected())
            .withConfigurationName("See favourite brands")
            .build();
    brandBrowser.show();
}