BulkEditAction

BulkEditAction is a list action designed to change attribute values for multiple entity instances at once. It opens a special screen where the user can enter desired attribute values. After that, the action updates the selected entities in the database and in the data container of the UI component.

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

Specific Parameters

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

  • openMode - the bulk edit screen opening mode as a value of the OpenMode enum: NEW_TAB, DIALOG, etc. By default, the screen is opened in the DIALOG mode.

  • columnsMode - the number of columns in the bulk edit screen as a value of the ColumnsMode enum. TWO_COLUMNS by default.

  • exclude - a regular expression to exclude entity attributes from displaying in the editor.

  • includeProperties - a list of entity attributes to be shown in the editor. This list has a higher priority than the exclude expression.

  • loadDynamicAttributes - whether to display dynamic attributes in the editor screen. The default value is true.

  • useConfirmDialog - whether to show a confirmation dialog before saving the changes. The default value is true.

For example:

<action id="bulk" type="bulkEdit">
    <properties>
        <property name="openMode" value="THIS_TAB"/>
        <property name="includeProperties" value="rewardPoints,email"/>
        <property name="columnsMode" value="ONE_COLUMN"/>
    </properties>
</action>

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

@Named("custTable.bulk")
private BulkEditAction custTableBulk;

@Subscribe
public void onInit(InitEvent event) {
    custTableBulk.setOpenMode(OpenMode.THIS_TAB);
    custTableBulk.setIncludeProperties(Arrays.asList("rewardPoints", "email"));
    custTableBulk.setColumnsMode(ColumnsMode.ONE_COLUMN);
}

Handlers and Events

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

fieldSorter

It is a handler that accepts the MetaProperty objects' list denoting entity attributes and returns a map of these objects to the desired index in the edit screen. For example:

@Install(to = "custTable.bulk", subject = "fieldSorter")
private Map<MetaProperty, Integer> custTableBulkFieldSorter(List<MetaProperty> properties) {
    Map<MetaProperty, Integer> result = new HashMap<>();
    for (MetaProperty property : properties) {
        switch (property.getName()) {
            case "email": result.put(property, 0); break;
            case "rewardPoints": result.put(property, 1); break;
            default:
        }
    }
    return result;
}

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. In the example below, we show a custom confirmation dialog before executing the action:

@Named("custTable.bulk")
private BulkEditAction custTableBulk;

@Subscribe("custTable.bulk")
public void onCustTableBulk(Action.ActionPerformedEvent event) {
    dialogs.createOptionDialog()
            .withCaption("Please confirm")
            .withMessage("Are you sure you want to edit the selected entities?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES)
                            .withHandler(e -> custTableBulk.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 BulkEditors API directly. 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 BulkEditors bulkEditors;
@Autowired
private Metadata metadata;
@Autowired
private GroupTable<Customer> custTable;

@Subscribe("custTable.bulkEdit")
public void onCustTableBulkEdit(Action.ActionPerformedEvent event) {
    bulkEditors.builder(metadata.getClass(Customer.class), custTable.getSelected(), this)
            .withListComponent(custTable)
            .withColumnsMode(ColumnsMode.ONE_COLUMN)
            .withIncludeProperties(Arrays.asList("rewardPoints", "email"))
            .create()
            .show();
}