ExcludeAction

ExcludeAction is a list action designed to remove entity instances from a data container in UI. Unlike RemoveAction, ExcludeAction does not remove the selected instance from the database. It is required, for example, when working with a many-to-many collection.

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

Properties

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

  • confirmation - boolean value specifying whether to show confirmation dialog before excluding the selected entities. The default value is true.

  • confirmationMessage - confirmation dialog message. By default, it is taken from the main message pack using the dialogs.Confirmation.Remove key.

  • confirmationTitle - confirmation dialog title. By default, it is taken from the main message pack using the dialogs.Confirmation key.

For example, if you want to show a specific confirmation message, you can configure the action in XML:

<action id="exclude" type="exclude">
    <properties>
        <property name="confirmation" value="true"/>
        <property name="confirmationTitle" value="Removing brand..."/>
        <property name="confirmationMessage"
                  value="Do you really want to remove the brand from the list?"/>
    </properties>
</action>

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

@Named("brandsTable.exclude")
private ExcludeAction<Brand> excludeAction;

@Subscribe
public void onInitEntity(InitEntityEvent<Customer> event) {
    excludeAction.setConfirmation(true);
    excludeAction.setConfirmationTitle("Removing brand...");
    excludeAction.setConfirmationMessage("Do you really want to remove the brand from the list?");
}

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.

afterActionPerformedHandler

It is a handler that is invoked after selected entities are removed. It accepts the event object that can be used to get the entities selected for removal. For example:

@Install(to = "brandsTable.exclude", subject = "afterActionPerformedHandler")
private void brandsTableExcludeAfterActionPerformedHandler(RemoveOperation.AfterActionPerformedEvent<Brand> event) {
    System.out.println("Removed " + event.getItems());
}

actionCancelledHandler

It is a handler that is invoked when the remove operation is cancelled by user in the confirmation dialog. It accepts the event object that can be used to get the entities selected for removal. For example:

@Install(to = "brandsTable.exclude", subject = "actionCancelledHandler")
private void brandsTableExcludeActionCancelledHandler(RemoveOperation.ActionCancelledEvent<Brand> event) {
    System.out.println("Cancelled");
}

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 custom confirmation dialog before executing the action:

@Subscribe("brandsTable.exclude")
public void onBrandsTableExclude(Action.ActionPerformedEvent event) {
    excludeAction.setConfirmation(false);
    dialogs.createOptionDialog()
            .withCaption("My confirm dialog")
            .withMessage("Do you really want to remove the brand from the list?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES)
                            .withHandler(e -> excludeAction.execute()), // execute action
                    new DialogAction(DialogAction.Type.NO)
            )
            .show();
}

You can also subscribe to ActionPerformedEvent, and instead of invoking the action’s execute() method, use RemoveOperation API directly to remove the selected entities. 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 RemoveOperation removeOperation;

@Subscribe("brandsTable.excludeAction")
public void onBrandsTableExcludeAction(Action.ActionPerformedEvent event) {
    removeOperation.builder(brandsTable)
            .withConfirmationMessage("Do you really want to remove the brand from the list?")
            .withConfirmationTitle("Removing brand...")
            .exclude();
}