3.5.5.2.2. 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 com.haulmont.cuba.gui.actions.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.
-
openMode
- the bulk edit screen opening mode as a value of theOpenMode
enum:NEW_TAB
,DIALOG
, etc. By default, the screen is opened inDIALOG
mode. -
columnsMode
- the number of columns in the bulk edit screen as a value of theColumnsMode
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 higher priority thanexclude
expression. -
loadDynamicAttributes
- whether to display dynamic attributes in the editor screen. True by default. -
useConfirmDialog
- whether to show a confirmation dialog before saving the changes. True by default.
For example:
<action id="bulkEdit" type="bulkEdit">
<properties>
<property name="openMode" value="THIS_TAB"/>
<property name="includeProperties" value="name,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("customersTable.bulkEdit")
private BulkEditAction customersTableBulkEdit;
@Subscribe
public void onInit(InitEvent event) {
customersTableBulkEdit.setOpenMode(OpenMode.THIS_TAB);
customersTableBulkEdit.setIncludeProperties(Arrays.asList("name", "email"));
customersTableBulkEdit.setColumnsMode(ColumnsMode.ONE_COLUMN);
}
The parameter below can be configured only in Java code. In order to generate correctly annotated method stub for it, use Handlers tab of the Component Inspector tool window in Studio.
-
fieldSorter
- a handler that accepts the list ofMetaProperty
object denoting entity attributes and returns a map of this objects to desired index in the edit screen. For example:@Install(to = "customersTable.bulkEdit", subject = "fieldSorter") private Map<MetaProperty, Integer> customersTableBulkEditFieldSorter(List<MetaProperty> properties) { Map<MetaProperty, Integer> result = new HashMap<>(); for (MetaProperty property : properties) { switch (property.getName()) { case "name": result.put(property, 0); break; case "email": result.put(property, 1); break; default: } } return result; }
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 execute()
method of the action when needed. In the example below, we show a custom confirmation dialog before executing the action:
@Named("customersTable.bulkEdit")
private BulkEditAction customersTableBulkEdit;
@Subscribe("customersTable.bulkEdit")
public void onCustomersTableBulkEdit(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 -> customersTableBulkEdit.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:
@Inject
private BulkEditors bulkEditors;
@Inject
private GroupTable<Customer> customersTable;
@Subscribe("customersTable.bulkEdit")
public void onCustomersTableBulkEdit(Action.ActionPerformedEvent event) {
bulkEditors.builder(metadata.getClassNN(Customer.class), customersTable.getSelected(), this)
.withListComponent(customersTable)
.withColumnsMode(ColumnsMode.ONE_COLUMN)
.withIncludeProperties(Arrays.asList("name", "email"))
.create()
.show();
}
The appearance of the bulk edit screen can be customized using SCSS variables with $c-bulk-editor-*
prefix. You can change these variables in the visual editor after creating a theme extension or a custom theme.