RemoveAction

RemoveAction is a list action designed to remove entity instances from a data container in UI and the database.

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

Properties

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

  • confirmation - boolean value specifying whether to show confirmation dialog before removing 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="remove" type="remove">
    <properties>
        <property name="confirmation" value="true"/>
        <property name="confirmationTitle" value="Removing customer..."/>
        <property name="confirmationMessage" value="Do you really want to remove the customer?"/>
    </properties>
</action>
<action id="removeAction" type="remove"/>

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

@Named("custTable.remove")
private RemoveAction<Customer> removeAction;

@Subscribe
public void onInit(InitEvent event) {
    removeAction.setConfirmation(true);
    removeAction.setConfirmationTitle("Removing customer...");
    removeAction.setConfirmationMessage("Do you really want to remove the customer?");
}

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 = "custTable.remove", subject = "afterActionPerformedHandler")
private void custTableRemoveAfterActionPerformedHandler(RemoveOperation.AfterActionPerformedEvent<Customer> event) {
    System.out.println("Removed " + event.getItems());
}

actionCancelledHandler

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

@Install(to = "custTable.remove", subject = "actionCancelledHandler")
private void custTableRemoveActionCancelledHandler(RemoveOperation.ActionCancelledEvent<Customer> event) {
    System.out.println("Cancelled");
}

Using ActionPerformedEvent

If you want to perform some checks or interact with the user in a special way 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:

@Named("custTable.remove")
private RemoveAction<Customer> removeAction;

@Subscribe("custTable.remove")
public void onCustTableRemove(Action.ActionPerformedEvent event) {
    removeAction.setConfirmation(false);
    dialogs.createOptionDialog()
            .withCaption("My confirm dialog")
            .withMessage("Do you really want to remove the customer?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES)
                            .withHandler(e -> removeAction.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("custTable.removeAction")
public void onCustTableRemoveAction(Action.ActionPerformedEvent event) {
    removeOperation.builder(custTable)
            .withConfirmationTitle("Removing customer...")
            .withConfirmationMessage("Do you really want to remove the customer?")
            .remove();
}