EntityOpenAction

EntityOpenAction is an entity picker action designed to open an editor screen for the entity currently selected in the entity picker.

The action is implemented by io.jmix.ui.action.entitypicker.EntityOpenAction class and should be defined in XML using type="entity_open" 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 EntityOpenAction class.

Properties

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

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

  • screenId - string id of the editor screen to use. By default, EntityOpenAction uses either a screen, annotated with @PrimaryEditorScreen, or having identifier in the format of <entity_name>.edit, for example, demo_Customer.edit.

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

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

<action id="open" type="entity_open">
    <properties>
        <property name="openMode" value="DIALOG"/>
        <property name="screenClass" value="ui.ex1.screen.entity.customer.CustomerEdit"/>
    </properties>
</action>

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

@Named("cEntityField.open")
private EntityOpenAction<Customer> openAction;

@Subscribe
public void onInit(InitEvent event) {
    openAction.setOpenMode(OpenMode.DIALOG);
    openAction.setScreenClass(CustomerEdit.class);
}

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 editor screen. For example:

@Install(to = "cEntityField.open", subject = "screenOptionsSupplier")
private ScreenOptions cEntityFieldOpenScreenOptionsSupplier() {
    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 editor screen and can initialize it before opening. For example:

@Install(to = "cEntityField.open", subject = "screenConfigurer")
private void cEntityFieldOpenScreenConfigurer(Screen screen) {
    ((CustomerEdit) screen).setSomeParameter(10);
}

afterCloseHandler

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

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

Using ActionPerformedEvent

If you want to perform some checks or interact with the user before the action is executed, subscribe to the action’s ActionPerformedEvent and invoke the execute() method of the action when needed. The action will be invoked with all parameters that you defined for it. In the example below, we show a confirmation dialog before executing the action:

@Subscribe("cEntityField.open")
public void onCEntityFieldOpen(Action.ActionPerformedEvent event) {
    dialogs.createOptionDialog()
            .withCaption("Please confirm")
            .withMessage("Do you really want to open the customer?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES)
                            .withHandler(e -> openAction.execute()), (1)
                    new DialogAction(DialogAction.Type.NO)
            )
            .show();
}
1 Execute action

You can also subscribe to ActionPerformedEvent, and instead of invoking the action’s execute() method, use ScreenBuilders API directly to open the edit screen. In this case, you are ignoring all specific action parameters and behavior and using only its common parameters like caption, icon, etc. For example:

@Autowired
private EntityPicker<Customer> cEntityField;

@Autowired
private ScreenBuilders screenBuilders;

@Subscribe("cEntityField.openAction")
public void onCEntityFieldOpenAction(Action.ActionPerformedEvent event) {
    screenBuilders.editor(cEntityField)
            .withOpenMode(OpenMode.DIALOG)
            .withScreenClass(CustomerEdit.class)
            .build()
            .show();
}